HY! 我正在向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;
}
}
}
答案 0 :(得分: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 + "]");
但是,您的代码没问题,您确定您的伺服器发送了响应吗?当您在浏览器中调用您的网址时,您有回复吗? 也许是一个解码问题......