开发者

Problem with HttpWebRequest and post URL containing values

I'm trying to post to a URL that looks something like this: "http://domain.com/api/?application_id=user&format=json&session_token=1824dsf1u312asd14"

I use the above as my request URL and write my data to the stream like this:

byte[] ByteQuery = Encoding.UTF8.GetBytes(post_body);
httpWebRequest.ContentLength = ByteQuery.Length;
Stream QueryStream = httpWebRequest.GetRequestStream();
QueryStream.Write(ByteQuery, 0, ByteQuery.Length);
QueryStream.Close();

That's all fine, the web page gets the post data no problem. The problem is that it returns an error like this:

{"stat":"fail","diagnostics":"0 2.6 25.22","error":{"code":6,"message":"method (usermgmt.add) cannot change application_id to (user) in the same request when set to (null-app)."}}

So my question is, how do I handle sending post data to this page? application_id has to be set in order to achieve my desired results. I have also tried sending it t开发者_如何学Chrough the RequestStream to no avail.

My post data as a string looks like this:

method=usermgmt.add&uid_to_add=5452007164&api_signature=&track=H40alhZWzp

The request I am trying to replicate: http://pastebin.com/c38Cq3AR


Try this:

using System.IO;
using System.Net;
using System.Text;
using System.Collections.Specialized;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var values = new NameValueCollection();
            values.Add("method", "usermgmt.add");
            values.Add("uid_to_add", "5452007164");
            values.Add("api_signature", "");
            values.Add("track", "H40alhZWzp");

            var wc = new WebClient();
            wc.Headers.Add(HttpRequestHeader.Cookie, "a=b&c=d");
            wc.Headers.Add(HttpRequestHeader.Referer, "http://www.tagged.com/meetme.html");

            var returnBytes = wc.UploadValues("http://domain.com/api/?application_id=user&format=json&session_token=1824dsf1u312asd14", values);
            var returnJson = Encoding.UTF8.GetString(returnBytes);
        }
    }
}

do you still get the same responde?

EDIT: probably the cookies and/or referrer counts here? If so, I've added them to the code...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜