本文介绍了在POST方法windows phone 7中为WebHeaderCollection添加标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器要求我们将包含设备ID的标题发布到服务器,通常我们可以这样做:

My server requires us to post a header that include device ID to server, normally we can do some thing like this:

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_connectionURL);
        request.ContentType = "application/x-www-form-urlencoded";

        request.Headers.Add    // THIS METHOD DOESN'T EXIST in windows phone 7
        request.Method = "POST";

它有这个方法,允许你设置可用的标题,但不包括我想要的标题在那里,我如何向WebHeaderCollection添加另一个标题。

It has this method, which allows you to set available headers, but the header I want is not included there, how can I add another header to WebHeaderCollection.

request.Headers.AllKeys.SetValue //this function to set the available headers.


推荐答案

request.Headers["MyHeaderName"] = "MyHeaderValue";

某些标头受限制,例如推荐人,并会抛出异常。

Some headers are restricted, such as Referrer, and will throw an exception.

这篇关于在POST方法windows phone 7中为WebHeaderCollection添加标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 11:39