2012-12-13 77 views

回答

2

每個瀏覽器都有一組用於監視HTTP請求的開發者工具。在Chrome中,您可以按ctrl + shift j,轉到網絡,並檢查當您點擊該頁面上的提交按鈕時使用的HTTP請求。大多數情況下,將數據發送到服務器將使用該站點所做的HTTP POST。重要的是查看它們用來發送POST數據的變量。該網站發送以下

ctl00$CPH4contentWindow$txtAddress:111 Street Name 

與內容類型的application/x-www-form-urlencoded

您可以嘗試通過發送這些信息你自己的HTTP請求來模擬這一點。

客戶

$.ajax({ 
    url: '/api/Address/111%20Street%20Name', 
    dataType: 'html', 
    success: function (result) { 
     // do something with result 
    } 
}); 

控制器

public class AddressController : ApiController 
{ 
    public string Get(string address) 
    { 
     WebClient client = new WebClient(); 
     client.AddHeader("content-type", "application/www-form-urlencoded"); 
     string response = client.UploadString("http://arcgis.dmgov.org/extmapcenter/addresslookup.aspx", "ctl00$CPH4contentWindow$txtAddress=" + Uri.EscapeDataString(address)); 
     return response; 
    } 
} 

如果你不需要它異步使用Ajax來發送你可以把邏輯控制器進入你的ASP.NET代碼在後面。

+0

這使用JQuery。順便說一下,只有在提出請求的頁面位於同一個域 - 相同的源策略 - http://en.wikipedia.org/wiki/Same_origin_policy。所以在這種情況下,他們都應該在http://arcgis.dmgov.org –

+0

哦,對。那麼他可以從他自己的Web Api控制器中繼請求並返回結果。我會更新答案,謝謝。 – Despertar

0

問題HTTP GET請求:http://support.microsoft.com/kb/307023

或使用iframe HTML標記,如果你想它在客戶端。

+0

恐怕我沒有讓自己清楚。我如何在我的請求中傳遞信息。就像我上面提到的鏈接的地址一樣。 –