Use charles to simulate Http requests and responses, and charles to simulate

Source: Internet
Author: User

Use charles to simulate Http requests and responses, and charles to simulate

The children's shoes on the server of the latest project team are too weak and the interfaces have never been available for convenient development. The children's shoes on the server have defined the http interface and the returned json structure. Then the client can use the json structure to simulate the data, and then perform smooth development. Finally, when the server interface is complete, perform joint debugging again.

This method has a professional name mock.

The following describes how to use mock http response.

For example, an http interface

Http://xx.oo.com/api/helloworld

The returned json structure is as follows.

{  "hello": "world"}
We can use the following website to simulate such a json response.

Http://dtjson.com/


Click Generate my HTTP Response to Generate a url. You can access this url to return the desired json string. The url generated in the json file I defined above is as follows. Click "access" to obtain the url.

Http://dtjson.com/v2/54c76c669663e6eb041a7281


So far, our fake interface has been completed, so do you want.

Of course not. We can use a tool, charles, which can act as a proxy for Android simulators or mobile phones and listen to all http accesses. It also has the ability to modify http requests and responses, very powerful.


For more information about charles, see Introduction.


In the android Simulator


The following is the http request result intercepted by charles. Here we can view the http protocol, including the request line and header file. But it is blank in the response tag, because the request has no response.



Set the request, right-click the request, and the following menu appears. Select Map Remote. Then fill in the proxy address that I need, click OK, and access again.


Then the access will be successful.





So far, all the steps for simulating request data have been completed. In actual development, as long as a simulated test is generated, You can smoothly skip the process of waiting for the interface and continue to work. When the interface is complete, remove the remote map settings, you can access the normal interface.



Related Article

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.