0

我正在尝试进行 POST 但每次都返回一个错误说

“远程服务器返回错误:未找到。”

我正在使用 Firefox 的 Firebug 扩展来获取 POST 方法的所有必要参数,但 firebug 说

“... Firebug 已达到 Firebug 请求大小限制。...”

. Wireshark 也或多或少说了同样的话。

我不知道是否需要(在 windows phone 7 HttpWebRequest 上)在标头上指定一些额外的参数,因为 POST 方法很长。

这是我的代码:

private void GetResponseCallbackAGCP(IAsyncResult asynchronousResult)
{
  Uri url = new Uri("http://publico.agcp.ipleiria.pt/Paginas/ScheduleRptCursosSemanalPublico.aspx");
 postData = "MSO_PageHashCode=" + _MSO_PageHashCode +
                "&__SPSCEditMenu=" + ___SPSCEditMenu +
                "&MSOWebPartPage_PostbackSource=" +
                "&MSOTlPn_SelectedWpId=" +
                "&MSOTlPn_View=0" +
                "&MSOTlPn_ShowSettings=" + _MSOTlPn_ShowSettings +
                "&MSOGallery_SelectedLibrary=" +
                "&MSOGallery_FilterString=" +
                "&MSOTlPn_Button=" + _MSOTlPn_Button +
                "&MSOAuthoringConsole_FormContext=" +
                "&MSOAC_EditDuringWorkflow=" +
                "&MSOSPWebPartManager_DisplayModeName=" + _MSOSPWebPartManager_DisplayModeName +
                "&__EVENTTARGET=" + _eventTarget +
                "&__EVENTARGUMENT=" + _eventArg +
                "&MSOWebPartPage_Shared=" +
                "&MSOLayout_LayoutChanges=" +
                "&MSOLayout_InDesignMode=" +
                "&MSOSPWebPartManager_OldDisplayModeName=" + _MSOSPWebPartManager_OldDisplayModeName +
                "&MSOSPWebPartManager_StartWebPartEditingName=" + _MSOSPWebPartManager_StartWebPartEditingName +
                "&__LASTFOCUS=" +
                "&__REQUESTDIGEST=" + ___REQUESTDIGEST +
                "&__VIEWSTATE=" + _viewState +
                "&__EVENTVALIDATION=" + _eventEval +
                "&ctl00%24ctl12%24ctl00=http%3A%2F%2Fspserver%3A7250" +
                "&ctl00%24PlaceHolderAGCPUO%24ddlUO=" + escolaSelected +
                "&ctl00%24PlaceHolderAGCPUO%24ddlAnosLectivos=" + anoLectivoSelected +
                "&ctl00%24PlaceHolderAGCPUO%24ddlPeriodos=" + periodoSelected +
                "&ctl00%24PlaceHolderMain%24ddlCursos=" + cursoSelected +
                "&ctl00%24PlaceHolderMain%24ddlAnosCurr=" + anoCurricularSelected +
                "&ctl00%24PlaceHolderMain%24ddlPlanos=" + planoSelected +
                "&ctl00%24PlaceHolderMain%24ddlRamos=" + troncoSelected +
                "&ctl00%24PlaceHolderMain%24ddlTurmas=" + turmaSelected +
                "&ctl00%24PlaceHolderMain%24txtObservacoesHor=" +
                "&ctl00%24PlaceHolderMain%24ddlZoom=1250" +
                "&ctl00%24PlaceHolderMain%24ddlSemanas=" + semanaSelected +
                "&ctl00_PlaceHolderMain_DayPilotCalendar1_vsupdate=" +
                "&ctl00_PlaceHolderMain_DayPilotCalendar1_scrollpos=" +
                "&ctl00_PlaceHolderMain_DayPilotCalendar1_select=" +
                "&__spDummyText1=__spDummyText1&__spDummyText2=__spDummyText2";

            cc = new CookieContainer();

            webRequest2 = (HttpWebRequest)WebRequest.Create(url);
            webRequest2.Method = "POST";
            webRequest2.ContentType = "application/x-www-form-urlencoded";
            webRequest2.CookieContainer = cc;

            webRequest2.BeginGetRequestStream(new AsyncCallback(GetRequestCallback), webRequest2);
}


   private void GetRequestCallback(IAsyncResult asynchronousResult)
        {
            var request = asynchronousResult.AsyncState as HttpWebRequest;
            StreamWriter stream = new StreamWriter(request.EndGetRequestStream(asynchronousResult));
            stream.Write(postData);
            stream.Flush();
            stream.Close();
            request.BeginGetResponse(AuthCallback, request);
        }

        private void AuthCallback(IAsyncResult asyncResult)
        {
            HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult); //RETURNS an error saying "WebException was unhandle. The remote server returned an error: NotFound."
            using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream()))
            {
                //string resultString = streamReader1.ReadToEnd();
                var info = streamReader1.ReadToEnd();
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    webView.NavigateToString(info);
                });

            }
        }

提前致谢!

4

2 回答 2

0

此异常也是由于防火墙刚刚关闭防火墙

转到控制面板\所有控制面板项\Windows 防火墙\自定义设置并关闭防火墙。

于 2013-06-27T09:46:10.077 回答
0

尝试使用 RestSharp,它大大简化了 Http 的东西。我一直在我所有的 WP7 项目中使用 RestSharp。

http://restsharp.org/

于 2012-06-18T01:43:55.883 回答