HttpURLConnection 的 POST 方法
<div style="padding-right: 5.4pt; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 4px; width: 95%; padding-top: 4px;">http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif URL url = new URL(".......");http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif HttpURLConnection con = (HttpURLConnection) url.openConnection();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif con.setDoOutput(true); // POST方式
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif con.setRequestMethod("POST");
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif OutputStream os = con.getOutputStream(); // 输出流,写数据
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif os.write("..........".getBytes());
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream())); // 读取结果
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif String line;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif while ((line = reader.readLine()) != null) ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif System.out.println(line);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif }
页:
[1]