Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9d5c655

Browse files
Update
1 parent c370cba commit 9d5c655

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

‎.idea/workspace.xml

Lines changed: 6 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
95 Bytes
Binary file not shown.

‎src/com/example/hello_world_package/Network_Programming_three.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ public static void main(String[] args) throws IOException {
1616
//creating a url, the url link denotes a php file that has some string value to be returned to this program when invoked
1717
URL url = new URL("http://adhikariaashish.com.np/Java_Network_Connection_demo.php");
1818

19-
//connecting to a url
20-
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
19+
20+
//If you call method openConnection() for a URL it returns an URLConnection object.
21+
URLConnection urlConnection = url.openConnection();
22+
23+
//Since we are using a url whose protocol is HTTP, we need to typecast this connection to HttpURLConnection first before operating
24+
HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
2125

2226
//Set the method for the URL request, one of: GET POST HEAD OPTIONS PUT DELETE TRACE are legal
2327
httpURLConnection.setRequestMethod("POST");
@@ -31,6 +35,8 @@ public static void main(String[] args) throws IOException {
3135
//getOutputStrream() returns the output stream of the URL connection for writing to the resource
3236
OutputStream outputStream = httpURLConnection.getOutputStream();
3337
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
38+
39+
//the string "Java_Program_Demo" is checked by the php file to decide whether to return the string value to this java program or not
3440
String post_data = URLEncoder.encode("type", "UTF-8") + "=" + URLEncoder.encode("Java_Program_Demo", "UTF-8");
3541
bufferedWriter.write(post_data);
3642
bufferedWriter.flush();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /