c# http请求方法名称"POST /sample.xml"

本文关键字:quot POST sample xml http 请求 方法 | 更新日期: 2023-09-27 18:10:07

Post样例xml方法异常消息:403

http请求名称编辑但不工作

        HttpWebRequest request;
        HttpWebResponse myHttpWebResponse;

        WebResponse rsp = null;

        Uri baseUri = new Uri("http://192.168.1.75:80");

        string postData = "<?xml version='"1.0'" encoding='"utf-8'" ?>"...";
        request = (HttpWebRequest)WebRequest.Create(baseUri.AbsoluteUri);
        //WebHeaderCollection myWebHeaderCollection = request.Headers;
        //myWebHeaderCollection.Add("Content-Type:text/xml charset=utf8");
        //myWebHeaderCollection.Add("Content-Length:124");

        request.Method = "POST /sample.xml";
        UTF8Encoding encoding = new UTF8Encoding();
        byte[] body = encoding.GetBytes(postData);
        request.ContentType = "text/xml charset=utf8";
        request.Accept = "text/html";
      //  request.Accept = "/setup.xml";
        request.ContentLength = body.Length;
        Stream newStream = request.GetRequestStream();
        newStream.Write(body, 0, body.Length);
        newStream.Close();

       myHttpWebResponse = (HttpWebResponse)request.GetResponse();
        myHttpWebResponse.Close();

右门柱:

POST/sample.xml HTTP/1.0的content - type: text/xml内容长度:124

请帮忙:

c# http请求方法名称"POST /sample.xml"

 request.Method = "POST /sample.xml";

应为

request.Method = "POST";

Uri baseUri = new Uri("http://192.168.1.75:80");

应该是

Uri baseUri = new Uri("http://192.168.1.75:80/sample.xml");

此外,处理程序/sample.xml必须存在于您的服务器上,并且a=必须接受POST请求。