0
我测试了这个代码,它第一次工作;现在我得到空的答复。但是,通过邮差,我可以得到答复。看来Json没有被正确读取。我收到400错误。HttpClient不在asp.net工作(在邮递员工作)
private Guid GetToken()
{
var client = new HttpClient();
var uri = "url";
var jsonInString = JsonConvert.SerializeObject(new Authorization());
var response = client.PutAsync(uri, new StringContent(jsonInString, Encoding.UTF8, "application/json")).Result;
var x = response.Content.ReadAsStringAsync().Result;
if(x=="")
return Guid.Empty;
return new Guid(response.Content.ReadAsStringAsync().Result);
}
public class Authorization
{
public string _x;
public Guid _y;
public Guid _z;
public long _a;
public long _b;
public Authorization()
{
x = 123; //dummy data
y = xx-xx-xx-xxxxx-xx-xxxx;
z = xx-xx-xx-xxxxx-xx-xxxx;
a = 123;
b = 123;
}
}
HTTP代码400停留在“错误的请求”。这意味着您的应用程序的后端无法处理给定的请求。也许你把Postman和你的真实应用混为一谈(Get/Post)。 – reporter
难道你忘记宣布运输方法了吗? – reporter
该方法是PUT,实际上我没有改变任何东西。这是正确的var response = client.PutAsync(uri,new StringContent(jsonInString,Encoding.UTF8,“application/json”))。 –