What is the correct URI for sending parameters via POST in WCF REST Services?

后端 未结 2 1740
我在风中等你
我在风中等你 2020-12-21 05:43

Let\'s say that I have specified the following WCF REST Service at the address \"http://localhost/MyRESTService/MyRESTService.svc\"

[ServiceContract]
public          


        
2条回答
  •  有刺的猬
    2020-12-21 06:19

    I had the same problem, and using Fiddler, I received a 403 (Bad Request) error every time I tried to post using the Body. The Fix, which took me a couple of hours to find is to change the Content Type to application/xml and send the body as an Xml.

    This is the line I used in the Header in Fiddler:

    Content-Type: application/xml;charset=UTF-8 
    

    Now I haven't used Microsoft.Http library, in my client I used WebRequest to do the post, and by setting the Content-Type to:

    request.ContentType = "application/xml;charset=UTF-8";
    

    Worked fine for me.

    Now if you want to use the URI to send parameters I recommend using WebGet instead of WebInvoke with POST.

提交回复
热议问题