Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
An exception occurred during a WebClient request in C#.when i run project got above error.How to solve this error?

var postdata = "ratepleplan&1250&roomtype&254";

using (WebClient client = new WebClient())
{

client.Headers[HttpRequestHeader.Accept] = "*/*";
client.Headers[HttpRequestHeader.Referer] = "https://dfddff.com/extranet/";
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded; charset=UTF-8";
client.Headers[HttpRequestHeader.ContentLength] = postdata.Length.ToString();
client.Headers[HttpRequestHeader.Cookie] = sessioncookie;
client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36";
//client.Headers.Add(HttpRequestHeader.Cookie, sessioncookie);
byte[] postArray = Encoding.ASCII.GetBytes(postdata);
byte[] response = client.UploadData("https://dfddff.com/rate", "POST", postArray); ==========> Got error
var responsehtml = Encoding.UTF8.GetString(response);
}
Posted
Comments
Krunal Rohit 13-Nov-15 6:16am    
What exception ?

-KR
SATHISH kumar 13-Nov-15 6:19am    
An exception occurred during a WebClient request
Afzaal Ahmad Zeeshan 13-Nov-15 6:26am    
Read the InnerException and tell us what that is.
SATHISH kumar 13-Nov-15 6:20am    
this line i got error


byte[] response = client.UploadData("dfddff.com/rate";, "POST", postArray); ==========> Got error –
SATHISH kumar 13-Nov-15 6:20am    
How can i solve?

1 solution

var postdata = "ratepleplan&1250&roomtype&254";


That's not valid post data, it has to be like this

var postdata = "ratepleplan=1250&roomtype=254";
 
Share this answer
 
Comments
SATHISH kumar 13-Nov-15 7:29am    
OK.But i got same error in that line

byte[] response = client.UploadData("dfddff.com/rate";, "POST", postArray); ==========> Got error –
F-ES Sitecore 13-Nov-15 7:57am    
You're not sending the write data or sending it in the wrong format, or there is an issue with the data you're sending. You'd need to find out why the remote service is throwing an error. Use a tool like Fiddler to inspect the network call and see if there is a more detailed error in the response you're getting back.

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