如何在webclient的post请求中发送x-www-form-urlencoded? [英] How to send x-www-form-urlencoded in a post request in webclient?

查看:25
本文介绍了如何在webclient的post请求中发送x-www-form-urlencoded?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以发送 json 但我找不到如何发送 x-www-form-urlencoded.我不知道该尝试什么,因为我找不到任何东西.

I know I can send json but I couldn't find how to send x-www-form-urlencoded. I don't know what to try as I couldn't find anything.

WebClient wc = new WebClient();


string data = "channel_id=+12039273888&channel_type=phone&channel_verification=514950";

wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

string result = wc.UploadString("http://3.86.171.88/api/login", data);

System.Console.WriteLine(result);

推荐答案

您可以在 WebClient 类上使用 UploadString() 方法,例如

You can use UploadString() method on WebClient class like

string data = "name=john&age=20&city=Uganda";
using (WebClient client = new WebClient())
{
    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
    string result = client.UploadString(url of api resource, data);
}

这篇关于如何在webclient的post请求中发送x-www-form-urlencoded?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆