-1
從未在之前調用過API,也不確定要在ASP.NET 中使用哪些類來完成此操作。我大概可以通過閱讀 調用其他服務的各種示例,但希望有人可以 建議哪些將更加具體到我的需要,所以我可以快速開始 的東西。用PHP腳本調用這個API的一個例子位於下面,所以如果有人可以使用HttpWebRequest和WebClient打出 的一些代碼,看到它的行動將是偉大的 爲所述的例子,以及從API捕獲答覆HttpRequest的。也有可能使用Jscript從客戶端/瀏覽器調用這些API,或者這些調用是否必須從服務器端進行,並將結果傳遞給客戶端?使用.Net 4.0,ASP.NET類調用簡單的外部/ Web服務API
OUTPUT: The API will output the fields below:
error If any error occurs while processing your request, this field will contain an error message. Otherwise, 'OK' will be returned.
eta It's a string containing the Estimated Time of Arrival
price The price charged to deliver the goods. GST is already included.
Note that in the output, fields will be line-separated (character '\n') and each line will contain a field name and respective value separated by '='. See example below.
error=OK
eta=Overnight
price=14.52
The following piece of code is a simple example of how to access our Calculator API using PHP.
<?
$calculator_url = "http://www.e-go.com.au/calculatorAPI";
/* from/to postcodes */
$pickup = 2000; //From Sydney
$delivery = 4000; //From Brisbane
/* Dimensions */
$width = 40;
$height = 35;
$depth = 65;
$weight = 2;
$ego_params = "?pickup=$pickup&delivery=$delivery";
$ego_params .= "&width=$width";
$ego_params .= "&height=$height&depth=$depth&weight=$weight";
$ego_quote = file($calculator_url . $ego_params);
foreach ($ego_quote as $num=>$quote) {
$quote = trim($quote);
$quote_field = explode("=", $quote);
print "Field=" . $quote_field[0] . "\tValue=" . $quote_field[1] . "\n";
}
?>
你想一個C#(ASP.NET)這個PHP腳本的版本? –
是的,使用MVC3,但我想這是所有的ASP.NET基礎設施。 – LaserBeak