Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 内容类型应用程序/x-www-form-urlencoded vs text/xml_Asp.net_Httpwebrequest - Fatal编程技术网

Asp.net 内容类型应用程序/x-www-form-urlencoded vs text/xml

Asp.net 内容类型应用程序/x-www-form-urlencoded vs text/xml,asp.net,httpwebrequest,Asp.net,Httpwebrequest,在我的应用程序中,在创建HttpWebRequest时,我们一直使用内容类型作为application/x-www-form-urlencoded,因为它只有一个URL和一个查询字符串,但现在我还需要发布一些XML数据。因此,我将XML数据作为字节添加到请求流中。我的问题是: 是否需要将contenttype更改为text/xml 若我这样做,查询字符串部分会发生什么 虽然我测试了内容类型,它运行良好,但我需要理解其含义。URL类似于http:\\somewebsite?someid=“te

在我的应用程序中,在创建
HttpWebRequest
时,我们一直使用内容类型作为
application/x-www-form-urlencoded
,因为它只有一个URL和一个查询字符串,但现在我还需要发布一些XML数据。因此,我将XML数据作为字节添加到请求流中。我的问题是:

  • 是否需要将contenttype更改为
    text/xml
  • 若我这样做,查询字符串部分会发生什么
虽然我测试了内容类型,它运行良好,但我需要理解其含义。URL类似于http:\\somewebsite?someid=“test” 在发送请求时

            //myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
            myHttpWebRequest.ContentType = "text/xml";
            string responseTxt = null;
            using (myWriter = myHttpWebRequest.GetRequestStream())
            {
                myWriter.Write(xmlbytes, 0, xmlbytes.Length);
            }
从请求中读取数据时

            someid = context.Request.QueryString["someid"].ToString();

                using (StreamReader rsp = new StreamReader(context.Request.InputStream))
                {
                    xml = rsp.ReadToEnd();
                }