$ HTTP service

Source: Internet
Author: User

$ HTTP is the Ajax service provided by angular.

It also involves

$ Httpbackend, $ httpprovider,

$ Q (angular promise ),

$ Cachefactory (angular cache mechanism) and so on

 

The first time I used the POST request yesterday, I encountered a tragedy when I went to data after the POST request was rejected by ashx.

I flipped through the source code.

The original problem lies in Content-Type.

Angular's default Content-Type is application/JSON, and we usually use application/X-WWW-form-urlencoded (this is also true for jquery)

  VaR Content_type_application_json = {'content-type': 'application/JSON; charset = UTF-8' }; Headers: {common :{ 'Accept': 'application/JSON, text/plain ,*/*' }, Post: shallowcopy (content_type_application_json ),  //  Shallowcopy is a shallowcopy.  Put: shallowcopy (content_type_application_json), Patch: shallowcopy (content_type_application_json )},  //  Transform outgoing request data Transformrequest :[ Function  (D ){  Return Isobject (d )&&! Isfile (d )&&! Isblob (d )? Tojson (d): D; // data will be processed as JSON}], 

In the case of. ashx, if we call content. request ["key"], we cannot obtain data.

We can solve this problem in the original way.

 
Streamreader reader =NewStreamreader (context. Request. inputstream, encoding. utf8 );StringJSON = reader. readtoend (); // This is data, which is a JSON array.

 

To be continued...

 

 

 

 

 

 

 

 



 



 

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.