问题描述:

I tested this code and it worked first time; now I get empty response. However, with Postman I am able to get the response. It seems that Json is not read correctly. I get back a 400 error.

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;

}

}

网友答案:

I managed to solve it. The problem was the name of the attributes in the Json object.

I used Resharper and tat renamed my variables in the Json object from Id to _id (note the underscore).

相关阅读:
Top