WP7上的POST请求 [英] POST Requests on WP7

查看:81
本文介绍了WP7上的POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经死了大约6个小时,试图弄清楚如何在WP7中发出常规POST请求,我尝试了此处和其他许多地方发布的类似问题的答案,还尝试了许多不同的API POST请求,它们都会导致一个特定的问题,

I've been dying for about 6 hours trying to figure out how to make a regular POST request in WP7 , I tried the answers of similar questions posted here and on many other places, I also tried many different APIs POST request, they all lead to one certain problem,

远程服务器返回错误:未找到.

The remote server returned an error: NotFound.

似乎每次都缺少一些东西.

it seems like everytime there's something missing.

因此,如果您愿意,请告诉我们如何在此WP7中正确获取POST请求

So, if you please someone show us how to properly get a POST request right in this WP7

推荐答案

我使用它发布到Facebook上没有任何问题:

I use this to post to facebook without any problem:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
request.Method = "POST";
request.BeginGetResponse((e) =>
{
    try
    {
        WebResponse response = request.EndGetResponse(e);
        // Do Stuff
    }
    catch (WebException ex)
    {
        // Handle
    }
    catch (Exception ex)
    {
        // Handle
    }
}, null);

我假设您已经尝试过此操作,因此可能与发布数据有关(上面的示例中没有,因为Facebook使用查询字符串).您能给我们更多信息吗?

I assume you would have tried this already so it may be something to do with the post data (which isn't in the above example as facebook uses the query string). Can you give us any more info?

这是一个编写帖子数据的(未经测试的)示例:

This is an (untested) example for writing post data:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
request.Method = "POST";
request.BeginGetRequestStream((e) =>
{
    using (Stream stream = request.EndGetRequestStream(e))
    {
        // Write data to the request stream
    }
    request.BeginGetResponse((callback) =>
    {
        try
        {
            WebResponse response = request.EndGetResponse(callback);
            // Do Stuff
        }
        catch (WebException ex)
        {
            // Handle
        }
        catch (Exception ex)
        {
            // Handle
        }
    }, null);
}, null);

这篇关于WP7上的POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆