如何调用异步任务框架3.5请帮帮我。我在我的3.5框架项目中调用此方法,它显示了一个错误。使用Framework 3.5发布json数据的任何alternet方式这是我的代码:
public async void APIPushStatusDriverPostion(string direction,string carColor,string supplier_company,string SupplierAccountId,string Karho_Ref,string booking_id,string vehicale_type, string vehicle_id, string vehicle_plate, double latitude, double longitude, string carModel, string status, string driver_id, string driver_phone, string driver_first_name, string driver_last_name)
{
APIKarhoBookingProperties objbooking = new APIKarhoBookingProperties();
objbooking.vehicle.vehicle_type = vehicale_type;
objbooking.vehicle.vehicle_id = vehicle_id;
objbooking.vehicle.vehicle_plate = vehicle_plate;
objbooking.vehicle.latitude = latitude;
objbooking.vehicle.longitude = longitude;
objbooking.vehicle.eta_minutes = "null";
objbooking.vehicle.make = "null";
objbooking.vehicle.model = carModel;
objbooking.vehicle.color = carColor;
objbooking.vehicle.status = status;
objbooking.vehicle.driver_id = driver_id;
objbooking.vehicle.driver_phone = driver_phone;
objbooking.vehicle.driver_phone = driver_first_name;
objbooking.vehicle.driver_last_name = driver_last_name;
var json = JsonConvert.SerializeObject(objbooking);
using (var response = await httpClient.PostAsync("{supplier_id}/availability?version=2", json))
{
string responseData = await response.Content.ReadAsStringAsync();
}
}
答案 0 :(得分:1)
使用3.5版本的.Net框架是不可能的。您的解决方案是:
WebClient
代替HttpClient
,然后使用HttpWebRequest
对象:以下是使用WebClient
类的示例。它可能无法正常运行,具体取决于您设置HttpClient
:
using (WebClient client = new WebClient())
{
string responseData = client.UploadString(host + "{supplier_id}/availability?version=2", json);
}