Click here to Skip to main content
15,897,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi every one check the below code its give me 403 error.
i m trying to call php website through API
when i am trying to debug the code and the controll come on Byte[] array its throw an error.. and when i try to copy and past ur http://IP/clients/includes/api.php[^]
please help thanks in adavace
its throw error authentication failed

public static string GetWHMCSAPIResults(string anaction)
{
// Instantiate the WebClient object
WebClient WHMCSclient = new WebClient();
string username = "DWCAPI";
string password = EncodeToMD5("123");
// Prepare a Name/Value collection to hold the post values
NameValueCollection form = new NameValueCollection();
form.Add("username", username);
form.Add("password", password); // the password will s ill need encoding is MD5 is a requirement
form.Add("action", anaction); // action performed by the API:Functions
form.Add("responsetype", "xml");

// Post the data and read the response
Byte[] responseData = WHMCSclient.UploadValues("http://IP/clients/includes/api.php", form);

// Decode and display the response.
//nsole.WriteLine("\nResponse received was \n{0}",
string result = System.Text.Encoding.ASCII.GetString(responseData);

if (result.Contains("result=error"))
{
result = null;
}

return result;

}
Posted
Updated 13-Aug-15 0:02am
v3
Comments
SundararamanS 12-Aug-15 9:19am    
if possible try to access the page using your web browser with the same parameters and see if you get proper response..
Razim Khan 13-Aug-15 0:22am    
http://IP/clients/includes/api.php when we call this from browser its successfully run but when we trying from API it give the error.
thanks for response
F-ES Sitecore 13-Aug-15 4:43am    
Use a tool like Fiddler to compare the request that works via the browser and the request that doesn't work via code. Try and make sure your code version matches it in terms of the header fields sent, the data in the body etc. Some things you might not think are relevant could be used by the target page to validate the request.
Razim Khan 13-Aug-15 6:23am    
thank you F-ES Sitecore , now when i try to copy past url in browser its give me authentication failled..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900