0

嗨!我正在从 wp7 向 php 发送请求。当 php 发送响应时,WP7 应用程序收到的响应包含大量空白字符和换行符。

这是我的 WP7 响应回调:

void GetResponseCallback(IAsyncResult asynchronousResult)
    {
        try
        {
            HttpWebRequest request = asynchronousResult.AsyncState as HttpWebRequest;
            HttpWebResponse response = request.EndGetResponse(asynchronousResult) as HttpWebResponse;
            using (StreamReader sr = new StreamReader(response.GetResponseStream()))
            {
                string responseText = sr.ReadToEnd();
                Debug.WriteLine(responseText);
                SaveResponseText(responseText);                  
            }
        }
        catch (WebException e)
        {
        }
    }

这是我的 php 代码详细信息:

if ($_POST["event"] == "riaszt")
  {
if($count != 0)
{         
    {
      echo ok;

    } 
}
 }
4

1 回答 1

0

我不知道这是否对您有帮助,但是对于所有响应的服务器,我使用此代码 =>

    HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
    // End the operation
    HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
    Stream streamResponse = response.GetResponseStream();
    StreamReader streamRead = new StreamReader(streamResponse);
    string responseString = streamRead.ReadToEnd();
    Debug.WriteLine("response ==> [" + responseString + "]");

但是,您的代码是好的,您确定您的服务器发送响应了吗?当您在浏览器中调用您的网址时,您有回应吗?可能是编码问题...

于 2012-07-26T08:27:53.003 回答