REST API测试:如何使用Google Chrome开发人员工具获得响应? [英] REST API Testing: How to get response using Google Chrome developer tools?

查看:171
本文介绍了REST API测试:如何使用Google Chrome开发人员工具获得响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对API测试非常陌生。



我正尝试使用Google Chrome的开发者工具来了解和探索此主题。



问题1:

是否可以使用chrome开发人员工具获取简单GET请求的响应(可能采用JSON格式) ?b / b>

我现在在做的是:

  • 打开Chrome开发者工具
  • 转到网络选项卡
  • 清除现有日志
  • 只需点击一个URL即可发送发布请求。例如 https://stackoverflow.com/questions/ask
  • 检查相应的文档加载
    < a href =https://i.stack.imgur.com/FwMua.png =nofollow noreferrer>

    b
    $ b b
    什么是相关性Reponse Headers 显示在上面的图像?我的意思是,我正确地认为这是我在完成GET请求后得到的响应吗?



    您可以给予的任何帮助或引用非常感谢!如果你想测试一个休息api我sugest你得到 postman 这是为了这个目的。



    回答您的问题:


    问题1:是否有可能获得使用chrome开发人员工具的简单GET请求的响应(可能采用JSON
    格式)?

    第一个要点清楚的是,它是将或不会向浏览器发送json响应的服务器。不是浏览器可以选择将任何响应视为json。



    如果发送GET请求,服务器响应一个json对象或json数组,并且 Content-type 头部被设置为 application / json ,你会看到在浏览器的主窗口中已经生成了响应。 / p>

    如果 Content-type 设置为 text / html ,例如,那么你仍然会在主窗口中得到一个json文本作为响应,但它不会很好地格式化。根据响应的发送方式,有时您可以通过左键单击浏览器窗口并选择查看源页面来查看它的格式。



    这个你不需要开发者的工具,除非你想看看接收响应需要多长时间,或者检查标题的某些特定值等,但是与接收响应或将其呈现在屏幕上无关。 p>

    如果您正在使用javascript / jquery和/或发送ajax请求(GET或POST),开发人员工具更加有用。在这些情况下,您可以调试该函数并查看ajax请求,以检查浏览器实际发生的情况以及接收到的响应情况。


    问题2:上面的
    图片显示的Reponse Headers的相关性是什么?我的意思是,我正确地认为这是在执行GET请求后我获得的响应吗?


    在你得到的回应是两件事情,头文件和内容。你看到的json对象是内容的一部分,而不是标题。

    标题会告诉浏览器,例如,body是 json (与html documenet或除了缓存控制等其他信息,或者主体的时间长度外,还有其他一些信息。



    搜索 http标题了解更多信息这是标准的标题。


    I'm very new to API testing.

    I'm trying to make use of Google Chrome's developer tools to understand and explore this subject.

    Question 1:
    Is it possible to get the response (possibly in JSON format) of a simple GET request using chrome developer tools?

    What I'm currently doing is:

  • Open chrome developer tools
  • Go to Network tab
  • Clear existing logs
  • Send a post request simply by hitting a URL. e.g. https://stackoverflow.com/questions/ask
  • Check the corresponding docs loaded

    Question 2:
    What are the relevance "Reponse Headers" shown on the image above? I mean, am I correct to think that this is the response I am getting after doing the GET request?

    Any help or references you can give are much appreciated!

    解决方案

    If you want to test a rest api I sugest you get postman which is meant for that purpose.

    Going to your questions:

    Question 1: Is it possible to get the response (possibly in JSON format) of a simple GET request using chrome developer tools?

    The first point to make clear is that it is the server who will or will not send a json response to the browser. Not the browser who can choose to see any response as json.

    If you send a GET request that the server responds with a json object or json array and the Content-type header is set to application/json, you will see that response already formated in the main window of the browser.

    If the Content-type is set to text/html, for example, then you will still get the a json text as response in the main window but it won't be nicely formated. Depending on how the response was sent, sometimes you can see it nicely formatted by left clicking the browser window and selecting view source page.

    For this you don't need developer's tools unless you want to see how long did it take to receive the response, or check the headers for some specific value, etc, but nothing to do with receiving the response or rendering it on screen.

    Developer's tools is more usefull if you are working with javascript/jquery and/or if you are sending ajax requests (GET or POST). In these cases you can debug the function and also see the ajax request to check what actually went out from your browser and what was received as a response.

    Question 2: What are the relevance "Reponse Headers" shown on the image above? I mean, am I correct to think that this is the response I am getting after doing the GET request?

    In the response you get the two things, the headers, and the content. The json objects you see are part of the content not the headers.

    The headers will tell the browser, for example, that the body is json (vs. an html documenet or something different), besides of other information like cache-control, or how long the body is.

    Search for http headers for more information on which are teh standard headers.

    这篇关于REST API测试:如何使用Google Chrome开发人员工具获得响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆