简体   繁体   English

无需ASP或Web服务调用即可集成asp.net服务

[英]integrate asp.net services without api or web service call

how do I send a request to a page that doesn't offer an API or web serviece like this one for example 如何将请求发送到不提供此类API或网络服务的页面

http://arcgis.dmgov.org/extmapcenter/addresslookup.aspx http://arcgis.dmgov.org/extmapcenter/addresslookup.aspx

from inside my asp.net webapplication. 从我的asp.net Web应用程序内部。

The problem is, how will I pass the information in my request. 问题是,我将如何传递请求中的信息。 in the case above for example, I need to pass the address. 例如,在上述情况下,我需要传递地址。

Each browser has a set of developer tools for monitoring HTTP requests. 每个浏览器都有一组用于监视HTTP请求的开发人员工具。 In Chrome you can hit ctrl+shift j, go to Network, and examine the HTTP request used when you hit the submit button on that page. 在Chrome中,您可以按ctrl + shift j,转到“网络”,然后检查在单击该页面上的“提交”按钮时使用的HTTP请求。 Most often sending data to the server will use an HTTP POST which that site does. 通常,将数据发送到服务器将使用该站点执行的HTTP POST。 What is important is to see the variables they use to send the POST data. 重要的是查看它们用于发送POST数据的变量。 That site sends the following 该站点发送以下内容

ctl00$CPH4contentWindow$txtAddress:111 Street Name

With a content-type of application/x-www-form-urlencoded 内容类型为application/x-www-form-urlencoded

You can try to mimic this by sending your own HTTP request with that information. 您可以尝试通过发送带有该信息的自己的HTTP请求来模仿此操作。

Client 客户

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

Controller 控制者

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;
    }
}

If you don't need it to be sent asynchronously with ajax you can just put the logic for the Controller into your ASP.NET code behind. 如果您不需要将其与ajax异步发送,则可以将Controller的逻辑放在后面的ASP.NET代码中。

You can use web browser addons like firebug for firefox to see what requests that page is making. 您可以使用诸如firebug的web浏览器插件(针对firefox)来查看该页面发出的请求。 For your sample case it is making a request to 对于您的示例案例,它正在请求

http://arcgis.dmgov.org/extmapcenter/AutoComplete.asmx/GetLocAddressList with prefixText to "textInsindeTextbox" http://arcgis.dmgov.org/extmapcenter/AutoComplete.asmx/GetLocAddressList ,其前缀文本为“ textInsindeTextbox”

make this request from your application. 从您的应用程序发出此请求。 But that webservice may not allow you do that. 但是该网络服务可能不允许您这样做。

Issue a HTTP GET request: http://support.microsoft.com/kb/307023 发出HTTP GET请求: http : //support.microsoft.com/kb/307023

or use IFRAME HTML tag if you want it on the client side. 或使用IFRAME HTML标记(如果要在客户端使用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM