我想將此jquery ajax調用轉換爲c#代碼。我可以知道如何轉換?如何將cquery中的jquery ajax調用#
$.ajax({
\t url: \t \t 'http://gothere.sg/maps/geo',
\t dataType: \t 'jsonp',
\t data: \t \t {
\t \t 'output' \t : 'json',
\t \t 'q' \t \t : address,
\t \t 'client' \t : '',
\t \t 'sensor' \t : false
\t },
\t type: \t 'GET',
\t success: function(data) {
\t \t \t \t
\t },
\t statusCode: {
\t \t 404: function() {
\t \t \t alert('Page not found');
\t \t }
\t },
});
我的C#代碼返回404如何在C#中指定數據類型和數據類型。 我可以知道如何在C#中傳遞這三個參數。
class Program
{
static void Main()
{
RunAsync().Wait();
}
static async Task RunAsync()
{
// TODO - Send HTTP requests
var url = "http://gothere.sg/maps/geo";
var dataType = "jsonp";
var type = "GET";
Console.WriteLine("Making API Call...");
using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate }))
{
client.BaseAddress = new Uri(url);
HttpResponseMessage response = client.GetAsync("data?output=json&q=550238&client=''&sensor=false").Result;
response.EnsureSuccessStatusCode();
string result = response.Content.ReadAsStringAsync().Result;
Console.WriteLine("Result: " + result);
}
Console.ReadLine();
}
}
感謝Pavan,它像一個魅力工作。 –
很高興幫助你@AlexAung –