简体   繁体   中英

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 snippet 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)
        {

        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM