【问题标题】:How to set a postvar's name in a httprequest?如何在 httprequest 中设置 postvar 的名称?
【发布时间】:2009-09-18 22:07:40
【问题描述】:

我需要访问一个响应 postvar“数据”的网络服务。 如何在 c# 中使用 httprequest 设置此名称... 这就是我得到的:

            UTF8Encoding encoding = new UTF8Encoding();
            byte[] data = encoding.GetBytes(postData); 

            HttpWebRequest myRequest =
              (HttpWebRequest)WebRequest.Create("http://secreturl/jubidubb.php");
            myRequest.Method = "POST";
            myRequest.ContentType = "application/x-www-form-urlencoded";
            myRequest.ContentLength = data.Length;
            myRequest.KeepAlive = true;
            Stream newStream = myRequest.GetRequestStream();


            newStream.Write(data, 0, data.Length);
            newStream.Close();

            // The response
            WebResponse response = myRequest.GetResponse();

【问题讨论】:

    标签: c# post web-services httprequest


    【解决方案1】:

    响应 postvar "data" 是否仅仅意味着您的 postData 字符串需要采用 "data=mydata" 的形式?

    【讨论】:

    • 如果不了解您正在使用的服务的规格,这是不可能的,但我猜您的postData 字符串需要采用data=my-json-encoded-data...的形式?
    • 我现在得到的数据是:{"name":"rox", "age":"20"}
    • 我需要做的就是给它一个邮编:P
    • 那就试试data={"name":"rox", "age":"20"}
    • 谢谢。明天试试看:)
    猜你喜欢
    • 1970-01-01
    • 2012-09-21
    • 1970-01-01
    • 2016-05-29
    • 2010-09-07
    • 2020-04-07
    • 2016-12-23
    • 2021-07-29
    • 1970-01-01
    相关资源
    最近更新 更多