Using x-www-form-urlencoded Content-Type in WCF
来源:互联网 发布:手机淘宝网 编辑:程序博客网 时间:2024/06/03 06:43
So we have a wcf restful web service configured with webHttpBinding and everything works fine with http get. If change it to Post and post something like variable1=1&variable2=2 in message body doesn't pick up the parameters. Is it possible to configure this to work in this situation?
To use the Stream format, you'd need to change your operation signature, as in the example below. With the new HTTP model (available in wcf.codeplex.com, and likely in the next version of the framework) you should be able to do it in a more elegant way.
public class Post_12293ed1_e89d_4376_8888_3d89896b5582 { [ServiceContract] public interface ITest { [OperationContract] void Process(Stream data); } public class Service : ITest { public void Process(Stream data) { string strData = new StreamReader(data).ReadToEnd(); NameValueCollection nvc = HttpUtility.ParseQueryString(strData); var username = nvc["username"]; var password = nvc["password"]; Console.WriteLine("User: {0}; password: {1}", username, password); } } public static void Test() { string baseAddress = "http://" + Environment.MachineName + ":8000/Service"; ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress)); WebHttpBinding binding = new WebHttpBinding(); host.AddServiceEndpoint(typeof(ITest), binding, "").Behaviors.Add(new WebHttpBehavior()); host.Open(); Console.WriteLine("Host opened"); string request = "username=John%20Doe&password=MySecretWord"; WebClient client = new WebClient(); client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; client.UploadString(baseAddress + "/Process", "POST", request); Console.Write("Press ENTER to close the host"); Console.ReadLine(); host.Close(); } }
0 0
- Using x-www-form-urlencoded Content-Type in WCF
- Content-Type: application/x-www-form-urlencoded
- [转]Content-Type: application/x-www-form-urlencoded
- Content-Type: application/x-www-form-urlencoded什么意思
- 关于 Content-Type:application/x-www-form-urlencoded
- 关于 Content-Type:application/x-www-form-urlencoded 和 Content-Type:multipart/related
- 关于 Content-Type:application/x-www-form-urlencoded 和 Content-Type:multipart/related
- 关于 Content-Type:application/x-www-form-urlencoded 和 Content-Type:multipart/related
- 关于 Content-Type:application/x-www-form-urlencoded 和 Content-Type:multipart/related
- 关于 Content-Type:application/x-www-form-urlencoded 和 Content-Type:multipart/related
- Content-Type:application/x-www-form-urlencoded 和 Content-Type:multipart/rel
- 关于 Content-Type:application/x-www-form-urlencoded 和 Content-Type:multipart/rel (2
- 关于 Content-Type:application/x-www-form-urlencoded 和 Content-Type:multipart/related
- 关于 Content-Type:application/x-www-form-urlencoded 和 Content-Type:multipart/related
- 关于 Content-Type:application/x-www-form-urlencoded 和 Content-Type:multipart/related
- Content-Type:application/x-www-form-urlencoded 和 multipart/form-data
- elasticsearch6.x {"error":"Content-Type header [application/x-www-form-urlencoded] is not supported"
- 解决Content-Type :application/x-www-form-urlencoded 老是request.getInputStream()取不到值的问题
- Android 全局设置应用字体样式
- 随机得到1-20之间的10个不相同的随机数
- js入门篇之正则表达式基础
- iBatis返回参数 记录
- 无权限弹提示
- Using x-www-form-urlencoded Content-Type in WCF
- [转]Android6.0权限适配之WRITE_EXTERNAL_STORAGE(SD卡写入)
- springMVC使用HandlerMethodArgumentResolver 自定义解析器实现请求参数绑定方法参数
- 求二维数组的鞍点
- 无论做什么,请一定要坚持,努力了,奋斗了,坚信一定可以成功!
- HTML-HEAD解析
- 1.Error:Error converting bytecode to dex:
- 关于MFC中ini的读写以及关于ini的遍历
- 【Android】【RecyclerView】各种LayoutManager划分割线