android 用Http请求网页源代码(get/post形式均已实现)【有截图附完整源码】

android 用Http请求网页源代码(get/post形式均已实现)【有截图附完整源码】
资源下载需要积分:2
  • 8202***@qq.com 开通了 钻石会员
    9小时前
  • 3679***@qq.com 开通了 铂金会员
    15小时前
  • 4302***@qq.com 开通了 钻石会员
    21小时前
  • 8277***@qq.com 开通了 永久会员
    1天前
  • 1905***@qq.com 开通了 钻石会员
    1天前
  • 8609***@qq.com 开通了 钻石会员
    1天前
  • 6497***@qq.com 开通了 钻石会员
    1天前
  • 5530***@qq.com 开通了 黄金会员
    2天前
  • 7793***@qq.com 开通了 永久会员
    2天前
  • 7897***@qq.com 开通了 黄金会员
    2天前
  • 6132***@qq.com 开通了 永久会员
    2天前
  • 2067***@qq.com 开通了 黄金会员
    2天前
  • 9673***@qq.com 开通了 黄金会员
    2天前
  • 2465***@qq.com 开通了 永久会员
    3天前
  • 3486***@qq.com 开通了 永久会员
    3天前
  • 9582***@qq.com 开通了 永久会员
    3天前
  • 7519***@qq.com 开通了 黄金会员
    3天前
  • 1763***@qq.com 开通了 黄金会员
    3天前
  • 源码分类:游戏源码
  • 发布日期:2020-03-25 21:21
  • 展示次数:1068
  • 下载次数:1
  • 收藏次数:1
  • 分享人员:cms插件分享

核心代码public class HttpActivity extends Activity {       private button mButton1, mButton2;     private textView mTextView1;       public void onCreate(Bundle savedInstanceState) {           super.onCreate(savedInstanceState);         setContentView(R.layout.main);           mButton1 = (Button) findViewById(R.id.myButton1);         mButton2 = (Button) findViewById(R.id.myButton2);         mTextView1 = (TextView) findViewById(R.id.myTextView1);           mButton1.setOnClicklistener(new Button.OnClickListener() {             public void onClick(View v) {                 String uriAPI = "http://www.sina.com";                   Httppost httpRequest = new HttpPost(uriAPI);                 List<NameValuePair> params = new ArrayList<NameValuePair>();                 params.add(new BasicNameValuePair("str", "post string"));                 try {                     httpRequest.setEntity(new URLEncodedFormEntity(params,                             HTTP.UTF_8));                     Httpresponse httpResponse = new DEFAULTHttpClient()                             .execute(httpRequest);                       if (httpResponse.getStatusLine().getStatusCode() == 200) {                           String strResult = EntityUtils.toString(httpResponse                                 .getEntity());                         mTextView1.setText(strResult);                     } else {                         mTextView1.setText("Error Response: "                                   httpResponse.getStatusLine().toString());                     }                 } catch (ClientProtocolException e) {                     mTextView1.setText(e.getMessage().toString());                     e.printStackTrace();                 } catch (IOException e) {                     mTextView1.setText(e.getMessage().toString());                     e.printStackTrace();                 } catch (Exception e) {                     mTextView1.setText(e.getMessage().toString());                     e.printStackTrace();                 }               }         });           mButton2.setOnClickListener(new Button.OnClickListener() {               public void onClick(View v) {                   String uriAPI = "http://www.sina.com";                   HttpGet httpRequest = new HttpGet(uriAPI);                 try {                       HttpResponse httpResponse = new DefaultHttpClient()                             .execute(httpRequest);                       if (httpResponse.getStatusLine().getStatusCode() == 200) {                           String strResult = EntityUtils.toString(httpResponse                                 .getEntity());                           strResult = eregi_replace("(\r\n|\r|\n|\n\r)", "",                                 strResult);                         mTextView1.setText(strResult);                     } else {                         mTextView1.setText("Error Response: "                                   httpResponse.getStatusLine().toString());                     }                 } catch (ClientProtocolException e) {                     mTextView1.setText(e.getMessage().toString());                     e.printStackTrace();                 } catch (IOException e) {                     mTextView1.setText(e.getMessage().toString());                     e.printStackTrace();                 } catch (Exception e) {                     mTextView1.setText(e.getMessage().toString());                     e.printStackTrace();                 }             }         });     }       public String eregi_replace(String strFrom, String strTo, String strTarget) {         String strPattern = "(?i)"   strFrom;         Pattern p = Pattern.compile(strPattern);         matcher m = p.matcher(strTarget);         if (m.find()) {             return strTarget.replaceAll(strFrom, strTo);         } else {             return strTarget;         }     } }

android 用Http请求网页源代码(get/post形式均已实现)【有截图附完整源码】

评论


亲,登录后才可以留言!

来源:android 用Http请求网页源代码(get/post形式均已实现)【有截图附完整源码】

李小萌资源网所有素材均为本站用户上传,仅供学习与参考,请勿用于商业用途,如有侵犯您的版权请联系客服服务QQ
本站提供各类程序源码素材。
如果对本站有任何意见请点击右侧侧边栏的反馈意见,我们会及时处理。

cms插件分享

cms插件分享

这个家伙很懒未写签名~