Created
May 15, 2014 15:51
-
-
Save hgoebl/9dcb663243db3f5fcbd3 to your computer and use it in GitHub Desktop.
Example using DavidWebb for [Stack Overflow 23678518](http://stackoverflow.com/questions/23678518/httppost-takes-more-than-3-sec-to-get-a-result)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.goebl.david; | |
import junit.framework.TestCase; | |
import org.json.JSONObject; | |
public class TestWebb_LocalStackoverflow23678518 extends TestCase { | |
public void testPost() throws Exception { | |
JSONObject register = new JSONObject(); | |
register.put("email", "[email protected]"); | |
register.put("password", "tiger"); | |
Webb webb = Webb.create(); | |
Response<JSONObject> response = webb | |
.post("http://secretserver.net/index.php") | |
.body(register) | |
.connectTimeout(3000) | |
.asJsonObject(); | |
if (response.isSuccess()) { | |
assertEquals(200, response.getStatusCode()); | |
assertNotNull(response.getBody()); | |
JSONObject outcome = response.getBody(); | |
System.out.println("userId=" + outcome.getString("userId")); | |
} else { | |
System.out.println(response.getStatusCode()); | |
System.out.println(response.getResponseMessage()); | |
System.out.println(response.getErrorBody()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment