如何使用HTTP GetAsync方法序列化反序列化对象?

时间:2016-08-04 14:12:07

标签: c# asp.net serialization .net-4.6

我将Web应用程序的框架从4.0升级到4.6后,我发现HTTP协议库中没有ReadAsAsync()方法,而ReadAsAsync()只有GetAsync()GetAsync()。我需要使用CustomResponse customResponse = client.ReadAsAsync("api/xxx", new StringContent(new JavaScriptSerializer().Serialize(request), Encoding.UTF8, "application/json")).Result; 序列化我的自定义对象。

使用ReadAsAsync()的代码:

CustomResponse customResponse = await Response.Content.ReadAsAsync<CustomResponse>(); 

另一个基于ReadAsAsync()

的示例
GetAsync()

如何使用private static final float SHIP_MAX_SPEED = 50f; //units per second private final Vector2 tmpVec2 = new Vector2(); private final Vector3 tmpVec3 = new Vector3(); //... if (Gdx.input.isTouched()) { camera.unproject(tmpVec3.set(Gdx.input.getX(), Gdx.input.getY(), 0)); //touch point to world coordinate system. tmpVec2.set(tmpVec3.x, tmpVec3.y).sub(x, y); //vector from ship to touch point float maxDistance = SHIP_MAX_SPEED * Gdx.graphics.getDeltaTime(); //max distance ship can move this frame if (tmpVec2.len() <= maxDistance) { x = tmpVec3.x; y = tmpVec3.y; } else { tmpVec2.nor().scl(maxDistance); //reduce vector to max distance length x += tmpVec2.x; y += tmpVec2.y; } } 方法实现相同的目标?

1 个答案:

答案 0 :(得分:3)

您可以这样使用它: (您可能希望在另一个线程上运行它以避免等待响应)

*data1