从Windows服务将数据发布到Web应用程序时出错。“远程服务器返回错误:(500)内部服务器错误。”

时间:2011-09-30 16:55:16

标签: c# windows-services

尝试从Windows服务向托管的Web应用程序发布数据时出现此错误。

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

            }

这是我的Windows服务的代码片段,它将数据发布到Web应用程序。 有没有人知道原因。我正在使用asp .Net C#

2 个答案:

答案 0 :(得分:1)

将您在C#中的请求与在浏览器中完成的请求进行比较。

使用fiddler执行此操作。

您应该能够比较标题值,完成帖子数据等所有内容,并能够找出您遗漏的内容。我怀疑你遗漏了所需的值,而服务器应用程序正在抛出(可能是意外的)异常。

答案 1 :(得分:0)

最后我得到了wat失踪。实际上我是在向Web应用程序发布数据并使用Request.QueryString读取它......实际上是如何读取Get Method。所以我的代码修改为

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

        }
相关问题