如何在web api客户端上使用json格式化程序 [英] how to use json formatters on web api client

查看:109
本文介绍了如何在web api客户端上使用json格式化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







这是我的代码:

Hi ,


This is my Code :

 public partial class Form1 : Form
{

string URI;
string email = ConfigurationSettings.AppSettings["email"].ToString();
string password = ConfigurationSettings.AppSettings["password"].ToString();

//LoginData ld = new LoginData();


public Form1()
{
InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)
{


}

private void submit_Click(object sender, EventArgs e)
{
URI = string.Concat(host.Text, api.Text);//textBox2.Text + textBox1.Text;

GetLogin();
}
#region Methods

private async void GetLogin()
{
using (var client = new HttpClient())
{

var login = new LoginData() { Email = email, Password =password };

var response = await client.PostAsJsonAsync(URI, login);
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

if (response.IsSuccessStatusCode)
{

var productJsonString = await response.Content.ReadAsStringAsync();


body.Text = productJsonString;

}

}

}
}
#endregion

public class LoginData
{
public string Email { get; set; }

public string Password { get; set; }

}

}





我想使用json格式化程序返回一个值



请给我一个代码



谢谢



I want to use json formatters for return a values

Please give me a code for that

Thank you

推荐答案

不确定你想要的是什么。您的问题,或者更确切地说,您对代码的需求并不明确。至少不是我。



如果你想要帮助的JSON语法,我建议你开始,例如,这里JSON教程 [ ^ ]以了解您的需求。

这是另一个开始的地方学习JSON [ ^ ]



之后你可以回来找一个更具体的问题。
Not sure exactly what it is you want. Your question, or rather, your demand for code is not clear. At least not to me.

If it is JSON syntax you want help with, I recommend that you start, for example, here JSON Tutorial[^] in order to learn about what you need.
Here is another place to start Learn JSON[^]

After that you can come back with a more specific question.


这篇关于如何在web api客户端上使用json格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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