Interface test postman and charles capture package

1. Interface Test

      ⑴

  Cookies: Cookies are special information sent by the server to the client, and the information is stored in the client in the form of a text file, and then the client will bring these special information each time it sends a request to the server. The storage time is 3 hours.


  session: The class corresponding to Session is javax.servlet.http.HttpSession class. Each visitor corresponds to a Session object, and all the client's state information is stored in this Session object. The Session object is created when the client first requests the server. Session is also a kind of key-value attribute pair, read and write customer status information through getAttribute (Stringkey) and setAttribute (String key, Objectvalue) method. The client's Session is obtained through the request.getSession () method in the Servlet, for example:

<span style="color:#333333"><code><%@ page language=<span style="color:#a31515">"java"</span> pageEncoding=<span style="color:#a31515">"UTF-8"</span>%>
<jsp:directive.page <span style="color:#0000ff">import</span>=<span style="color:#a31515">"com.helloweenvsfei.sessionWeb.bean.Person"</span>/>
<jsp:directive.page <span style="color:#0000ff">import</span>=<span style="color:#a31515">"java.text.SimpleDateFormat"</span>/>
<jsp:directive.page <span style="color:#0000ff">import</span>=<span style="color:#a31515">"java.text.DateFormat"</span>/>
<jsp:directive.page <span style="color:#0000ff">import</span>=<span style="color:#a31515">"java.util.Date"</span>/>
<%!
DateFormat dateFormat = newSimpleDateFormat(<span style="color:#a31515">"yyyy-MM-dd"</span>); <span style="color:green">// 日期格式化器</span>
%>
<%
response.setCharacterEncoding(<span style="color:#a31515">"UTF-8"</span>); <span style="color:green">// 设置request编码</span>
Person[] persons =
{
<span style="color:green">// 基础数据,保存三个人的信息</span>
<span style="color:#0000ff">new</span> Person(<span style="color:#a31515">"Liu Jinghua"</span>,<span style="color:#a31515">"password1"</span>, 34, dateFormat.parse
(<span style="color:#a31515">"1982-01-01"</span>)),
<span style="color:#0000ff">new</span> Person(<span style="color:#a31515">"Hello Kitty"</span>,<span style="color:#a31515">"hellokitty"</span>, 23, dateFormat.parse
(<span style="color:#a31515">"1984-02-21"</span>)),
<span style="color:#0000ff">new</span> Person(<span style="color:#a31515">"Garfield"</span>, <span style="color:#a31515">"garfield_pass"</span>,23, dateFormat.parse
(<span style="color:#a31515">"1994-09-12"</span>))
};

String message = <span style="color:#a31515">""</span>; <span style="color:green">// 要显示的消息</span>

<span style="color:#0000ff">if</span>(request.getMethod().equals(<span style="color:#a31515">"POST"</span>))
{
<span style="color:green "> // If it is POST login </ span> <span style = "color: green"> // If the user name is correct and the password is correct </ span><span style =" color: green "> // traversal basics Data, verify account number and password </ span>{
<span style =" color: # 0000ff "> for </ span> (Person person: persons)



<span style="color:#0000ff">if</span>(person.getName().equalsIgnoreCase(request.getParameter(<span style="color:#a31515">"username"</span>))&&person.getPassword().equals(request.getParameter(<span style="color:#a31515">"password"</span>)))
{
<span style="color:green">// 登录成功,设置将用户的信息以及登录时间保存到Session</span>
session.setAttribute(<span style="color:#a31515">"person"</span>, person); <span style="color:green">// 保存登录的Person</span>
session.setAttribute(<span style="color:#a31515">"loginTime"</span>, <span style="color:#0000ff">new</span> Date()); <span style="color:green">// 保存登录的时间 </span>
response.sendRedirect(request.getContextPath() + <span style="color:#a31515">"/welcome.jsp"</span>);
<span style="color:#0000ff">return</span>;
}
}
message = <span style = "color: # a31515"> "Username and password do not match, login failed." </ span>; <span style = "color: green"> // Login failed </ span>
}
%>
<! DOCTYPE HTML PUBLIC <span style = "color: # a31515"> "-// W3C // DTD HTML 4.01Transitional // EN" </ span >>
<html>
<span style = "color: green"> / / ... HTML code is a FORM form, the code is abbreviated, please see the CD with the book </ span>
</ html> </ code> </ span>

  ⑵

  get request

  Used to get data from the server

  post request

  Used to send data to the server
  

  url
  request header
  stores some additional information
  what browser is used. .
  Request body
  sent data

  The get request has no request body, and its data is that the
  get request placed in the url is not secure, and the post request is safer.
  The data transmitted by the get request is not as much as the data transmitted by the post request.

 

HTTP:

1xx (provisional response) indicates a status code that temporarily responds and requires the requester to continue the operation.
  • 100 (Continued) The requester shall continue to make requests. The server returns this code to indicate that it has received the first part of the request and is waiting for the rest.
  • 101 (switching protocol) The requester has requested the server to switch the protocol, and the server has confirmed and is ready to switch.
  • 102 Status code extended by WebDAV (RFC 2518), which means that processing will continue to be performed.
2xx (success) indicates that the status code of the request was successfully processed.
  • 200 (Success) The server has successfully processed the request. Usually, this means that the server provided the requested web page.
  • 201 (Created) The request was successful and the server created a new resource.
  • 202 (Accepted) The server has accepted the request, but has not yet processed it.
  • 203 (Unauthorized Information) The server has successfully processed the request, but the information returned may come from another source.
  • 204 (No content) The server successfully processed the request but returned nothing.
  • 205 (Reset content) The server successfully processed the request but returned nothing.
  • 206 (Partial content) The server successfully processed part of the GET request.
  • 207 The status code extended by WebDAV (RFC 2518) represents that the subsequent message body will be an XML message, and may contain a series of independent response codes according to the number of previous sub-requests.
3xx (Redirect) indicates that further action is required to complete the request. Usually, these status codes are used for redirection.
  • 300 (multiple choices) The server can perform various operations in response to requests. The server may select an operation according to the requester (useragent), or provide an operation list for the requester to select.
  • 301 (Permanently Moved) The requested webpage has been permanently moved to a new location. When the server returns this response (in response to a GET or HEAD request), it will automatically transfer the requester to the new location.
  • 302 (Temporary Mobile) The server is currently responding to requests from web pages in different locations, but the requester should continue to use the original location for future requests.
  • 303 (see other locations) When the requester should use a separate GET request to retrieve the response for different locations, the server returns this code.
  • 304 (Unmodified) Since the last request, the requested webpage has not been modified. When the server returns this response, it will not return the content of the web page.
  • 305 (Use proxy) The requester can only use the proxy to access the requested web page. If the server returns this response, it also indicates that the requester should use a proxy.
  • 307 (Temporary redirect) The server currently responds to requests from web pages in different locations, but the requester should continue to use the original location for future requests.
4xx (Request error) These status codes indicate that the request may be in error, which prevents the server from processing.
  • 400 (Bad request) The server does not understand the syntax of the request.
  • 401 (Unauthorized) The request requires authentication. For web pages that require login, the server may return this response.
  • 402 The status code is reserved for possible future needs.
  • 403 (Forbidden) The server rejected the request.
  • 404 (Not Found) The server cannot find the requested page.
  • 405 (Method disabled) Disable the method specified in the request.
  • 406 (Not accepted) Unable to respond to the requested webpage with the requested content characteristics.
  • 407 (agent authorization required) This status code is similar to 401 (unauthorized), but specifies that the requestor should authorize the use of an agent.
  • 408 (Request timeout) The server timed out while waiting for the request.
  • 409 (Conflict) The server encountered a conflict while completing the request. The server must include information about the conflict in the response.
  • 410 (Deleted) If the requested resource has been permanently deleted, the server will return this response.
  • 411 (requires effective length) The server does not accept requests without the effective content length header field.
  • 412 (Prerequisite not met) The server did not meet one of the prerequisites set by the requester in the request.
  • 413 (The request entity is too large) The server cannot process the request because the request entity is too large and exceeds the processing capacity of the server.
  • 414 (Requested URI is too long) The requested URI (usually a URL) is too long for the server to process. This is relatively rare, and the usual circumstances include: the form submission that should use the POST method becomes the GET method, resulting in a query string (Query String) that is too long.
  • 415 (Unsupported media type) The requested format is not supported by the requested page.
  • 416 (The requested range does not meet the requirements) If the page cannot provide the requested range, the server returns this status code.
  • 417 (Expectations not met) The server did not meet the requirements of the "Expectations" request header field.
5xx (Server Error) These status codes indicate that the server encountered an internal error while trying to process the request. These errors may be the server's own error, rather than the request error.
  • 500 (Internal server error) The server encountered an error and could not complete the request.
  • 501 (Not yet implemented) The server does not have the function to complete the request. For example, this code may be returned when the server does not recognize the request method.
  • 502 (Bad gateway) The server acting as a gateway or proxy received an invalid response from the upstream server.
  • 503 (Service unavailable) The server is currently unavailable (due to overload or downtime maintenance). Usually, this is only a temporary state.
  • 504 (Gateway timeout) The server acts as a gateway or proxy, but did not receive the request from the upstream server in time.
  • 505 (HTTP version is not supported) The server does not support the HTTP protocol version used in the request.

 

2.postman

       ①Parameterization:
  Variable parameterization {{value}}, the separator is saved with a comma, no separator is added at the end, and the garbled problem is saved as a selection utf-8 to save the review

  

 

 

    Note: The number of runs is equal to the number of lines in the parameterized script and will not be run iteratively

  

  ② (Dynamic and static) checkpoints:

 

 

 

 

   Select Response body: Contains String static check ( pm.test ("Body matches string", function () { pm.expect (pm.response.text ()). To.include ("string_you_want_to_search"); }); ); Click Get a variable to appear (pm.variables.get ("variable_key"); put in static pm.test ("Body matches string", function () { pm.expect (pm.response.text ()). To .include ("string_you_want_to_search"); }); Need to check the brackets of the string.

  ③Quasi matching:

  

 

 

 

 

 Take the parameter "28800" in expire-time in the result dictionary

 

3.Charles capture use
   

     

 

Guess you like

Origin www.cnblogs.com/shine0824/p/12703282.html