代码之家  ›  专栏  ›  技术社区  ›  vikramvi

cURL with——数据二进制文件尝试自动执行时抛出500个错误

  •  0
  • vikramvi  · 技术社区  · 8 年前

    我的卷曲如下

    curl -H 'Host: api.staging.test.com' -H 'accept: application/json' -H 'content-type: application/json; charset=utf-8' -H 'user-agent: okhttp/3.10.0' --data-binary '{"emailId":"test@test.com","password":"test123"}' --compressed 'https://api.staging.test.com/user/develop-account/v1/session?storeId=100'
    

    我正试着用 rest-assured 如下所示

    request = given().
                            log().all().
                                    auth().basic("test@test.com", "test123").
                                    header("Host", HOST_HEADER).
                                    header("user-agent", USER_AGENT).
                                    header("accept", ACCEPT).
                                    header("content-type", CONTENT_TYPE);
    
    response = request.when().
               post("https://api.staging.test.com/user/develop-account/v1/session?storeId=100");
    
      json = response.then().statusCode(200);
    

    1 回复  |  直到 8 年前
        1
  •  0
  •   vikramvi    7 年前

    我可以用下面的代码让它工作

    Map<String, Object> params = new HashMap<>();
    params.put("emailId", "test@test.com");
    params.put("password", "test123");
    
    request = given().
                    log().all().
                            header("Host", HOST_HEADER).
                            header("user-agent", USER_AGENT).
                            header("accept", ACCEPT).
                            header("content-type", CONTENT_TYPE).
                            contentType(JSON).
                            body(params);
    
    response = request.when().
                            post(ENDPOINT_FOR_LOGIN);
    
    
    json = response.then().statusCode(200);
    
    
    
    import static io.restassured.http.ContentType.JSON;
    
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.4</version>
        <scope>test</scope>
    </dependency>
    
    推荐文章