[英]integrate asp.net services without api or web service call
如何将请求发送到不提供此类API或网络服务的页面
http://arcgis.dmgov.org/extmapcenter/addresslookup.aspx
从我的asp.net Web应用程序内部。
问题是,我将如何传递请求中的信息。 例如,在上述情况下,我需要传递地址。
每个浏览器都有一组用于监视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异步发送,则可以将Controller的逻辑放在后面的ASP.NET代码中。
您可以使用诸如firebug的web浏览器插件(针对firefox)来查看该页面发出的请求。 对于您的示例案例,它正在请求
http://arcgis.dmgov.org/extmapcenter/AutoComplete.asmx/GetLocAddressList ,其前缀文本为“ textInsindeTextbox”
从您的应用程序发出此请求。 但是该网络服务可能不允许您这样做。
发出HTTP GET请求: http : //support.microsoft.com/kb/307023
或使用IFRAME HTML标记(如果要在客户端使用)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.