The WebService request appears. "The request format cannot be recognized because the URL ends unexpectedly." SOLUTION

Source: Internet
Author: User

Recently I 've been playing with jeasyui. It's easy to use, but it's so convenient that it's less flexible.

When a DataGrid in jeasyui is used to request a WebService (asmx file), the following error occurs:

Local Development and debugging, can request data to the server normally;

After being published to IIS, the client cannot access the data;

Make a local access to the server and request data .)

When jquery Ajax is used to request a WebService (asmx file), it remains normal.

Development Environment: vs2008 in Windows XP

JS framework: jquery-1.7.2.min.js

Jquery. easyui. Min. js

View --------------- with firebug because the URL ends unexpectedly with "/xxxxxxxxxx", the request format cannot be identified.

Instructor Gu said:

Add the following content to the <system. Web> node of WebService::

<WebServices>
<Protocols>
<Add name = "httppost"/>
<Add name = "httpget"/>
</Protocols>
</WebServices>

Let's take a look at the two requests and the return process using firebug and compare the results,

Easyui DataGrid request:
Headers:
Responseheaders:
// Manually set context. response. contenttype = "application/JSON; charset = UTF-8" on the server side ";
// If this parameter is not set, the following content-type does not exist.
Server ASP. NET development server/9.0.0.0
Content-Type application/JSON; charset = UTF-8

Requestheaders:
Content-Type application/X-WWW-form-urlencoded; charset = UTF-8 // application/X-WWW-form-urlencoded (Form submitted using the http post method)
Accept application/JSON, text/JavaScript, */*; q = 0.01
X-requested-with XMLHttpRequest

Post:
Parameters: Application/X-WWW-form-urlencoded
Invs_id 1041 // This is a parameter,

JSON: // JSON has no data,

Source:
Invs_id = 1041 // note the format
Bytes -----------------------------------------------------------------------------------------------------

Jquery Ajax request:

Headers:
Responseheaders:
Server Microsoft-IIS/6.0
Responseheaders: Content-Type application/JSON; charset = UTF-8
Accept application/JSON, text/JavaScript, */*; q = 0.01
X-requested-with XMLHttpRequest

Post:
// Parameters
JSON // JSON has data
Invsid 1041 // This is a parameter

Source
{Invsid: 1041} // note the format

Easyui requests (jquery Ajax requests at the underlying layer). If Content-Type is not set, application/X-WWW-form-urlencoded is added by default;

Cause: Because the URL ends unexpectedly with "/xxxxxxxxxx", the request format cannot be identified. The reason must be that the Content-Type is application/X-WWW-form-urlencoded;

But why does the client fail to access the server when the local computer can request data? (......)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.