Error While posting Data to a web application from a windows service."The remote server returned an error: (500) Internal Server Error."
I'm getting this error while trying to post data to a hosted web application from a windows service.
PostSubmitter post = new PostSubmitter();
post.Url = "http://192.168.0.1/Invoice/Invoice1.aspx";
post.PostItems.Add("subscriberid", subscriberid.ToString());
post.PostItems.Add("StartDate", StartDate);
post.PostItems.Add("EndDate", EndDate);
post.PostItems.Add("AdvanceBillDate", AdvanceBillDate);
post.Type = PostSubmitter.PostTypeEnum.Post;
try
{
string res = post.Post();
}
catch (Exception exp)
{
}
This is code 开发者_如何学Csnippet of my windows service which posts data to web application. Does any one know the reason.I'm using asp .Net C#
Compare your request from C# with one done in a browser.
Use fiddler to do this.
You should be able to compare everything from header values, to complete post data, etc. and be able to figure out what you have missing. I would suspect you are leaving out required a value and the server application is throwing a (likely unexpected) exception.
Finally i got wat was missing.Actually i was posting data to the web application and reading it using Request.QueryString......Which is actually how Get Method is read.So modified my code as
PostSubmitter post = new PostSubmitter();
post.Url = "http://192.168.0.1/Invoice/Invoice1.aspx";
post.PostItems.Add("subscriberid", subscriberid.ToString());
post.PostItems.Add("StartDate", StartDate);
post.PostItems.Add("EndDate", EndDate);
post.PostItems.Add("AdvanceBillDate", AdvanceBillDate);
post.Type = PostSubmitter.PostTypeEnum.Get;
try
{
string res = post.Post();
}
catch (Exception exp)
{
}
精彩评论