Skip to content

Commit 944e3f5

Browse files
author
Echo.Xu
committed
add https demo
1 parent 4bfcbc4 commit 944e3f5

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ System.out.println(jsonobj.asObject().get("id").toString());
3838

3939
### Problems
4040

41-
- cannot support https
41+
- support https on 20210612

src/ws/http/Request.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Request extends Message<Request> {
2121
/**
2222
* enable debug to print log
2323
*/
24-
boolean enableDebug = true;
24+
boolean enableDebug = false;
2525

2626
HttpURLConnection connection;
2727
OutputStreamWriter writer;
@@ -156,6 +156,18 @@ public Request setTimeout(int connectTimeout, int readTimeout)
156156
return this;
157157
}
158158

159+
/**
160+
* enable Debug
161+
*
162+
* @param enableDebug
163+
* @return
164+
*/
165+
public Request enableDebug(boolean enableDebug)
166+
{
167+
this.enableDebug = enableDebug;
168+
return this;
169+
}
170+
159171
/**
160172
* Adds a Query Parameter to a list. The list is converted to a String and appended to the URL when the Request
161173
* is submitted.

src/ws/http/test/TestCase.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class TestCase {
1717

1818
public static void main(String[] args) throws IOException {
1919
TestCase obj = new TestCase();
20-
// obj.testGet();
20+
obj.testGet();
2121
obj.testHttpsGet();
2222
// obj.testPost();
2323
// obj.testJson();
@@ -64,21 +64,17 @@ public void testJson()
6464
public void testGet() throws IOException
6565
{
6666
Response httpResponse = new Request("http://ip-api.com/json/24.48.0.1")
67+
.enableDebug(true)
6768
.addHeader("Content-Type", "application/json").getResource();
6869

69-
logger.info(httpResponse.toString());
70-
71-
String responseBody = httpResponse.getBody();
72-
73-
logger.info(JSON.stringify(responseBody));
74-
7570
}
7671

7772
public void testHttpsGet() throws IOException
7873
{
7974
String url = "https://www.chope.co:443/singapore-restaurants/category/get_top_search?restaurant_keyword=&_=1623464304035";
8075

8176
Response httpResponse = new Request(url)
77+
.enableDebug(true)
8278
.addHeader("Content-Type", "application/json").getResource();
8379

8480
// logger.info(httpResponse.toString());

0 commit comments

Comments
 (0)