在下面代码的按钮点击事件中,我现在可以将我的数据发送到API控制器的后期操作 按钮单击Windows窗体的事件
private void button1_Click(object sender, EventArgs e)
{
WebClient client = new WebClient();
client.Headers[HttpRequestHeader.ContentType] = "application/json";
MyClass myClass = new MyClass();
myClass.SearchText = textBox1.Text;
myClass.CountryCode = textBox2.Text;
string serialisedData = JsonConvert.SerializeObject(myClass);
var response = client.UploadString("http://localhost:50232/api/Place/PostSimple", serialisedData);
var x= JsonConvert.DeserializeObject(response);
}
}
public class MyClass
{
public string SearchText { get; set; }
public string CountryCode { get; set; }
}
但是在调试时,我无法移动
GeocodingResponse geocode = GoogleMaps.Geocode.Query(geocodeRequest);
这一行的PostSimple动作方法。并在
中获得例外 var response = client.UploadString("http://localhost:50232/api/Place/PostSimple", serialisedData); of Windows form application as
抛出异常:System.dll中的“System.Net.WebException”
其他信息:操作已超时
ApiController代码
[HttpPost]
public List<Place> PostSimple(MyClass value)
{
List<Place> list = new List<Place>();
var geocodeRequest = new GeocodingRequest
{
Address = value.SearchText,
Components = new GeocodingComponents()
{
Country = value.CountryCode
}
};
try
{
GeocodingResponse geocode = GoogleMaps.Geocode.Query(geocodeRequest);
if (geocode.Status == GoogleMapsApi.Entities.Geocoding.Response.Status.OK)
{
TimeZoneRequest request = new TimeZoneRequest();
request.Location = new Location(geocode.Results.First().Geometry.Location.Latitude, geocode.Results.First().Geometry.Location.Longitude);
request.Language = "en";
request.TimeStamp = DateTime.Now.AddDays(-60);
TimeZoneResponse result = GoogleMaps.TimeZone.Query(request);
var x = System.TimeZoneInfo.FindSystemTimeZoneById(result.TimeZoneName);
}
}
catch (Exception ex)
{
throw ex;
}
return list;
}
MyClass代码
public class MyClass
{
public string SearchText { get; set; }
public string CountryCode { get; set; }
}
任何人都可以帮我解决这个问题。谢谢你提前