开发学院手机开发Android 开发 Android HttpConnect 阅读

Android HttpConnect

 2010-10-19 20:17:34 来源:WEB开发网   
核心提示:43. List < NameValuePair> params = new ArrayList< NameValuePair>();44. params.add(new BasicNameValuePair("str", "i am post string&quo

43. List < NameValuePair> params = new ArrayList< NameValuePair>();

44. params.add(new BasicNameValuePair("str", "i am post string"));

45.

46. try {

47. httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));

48. HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);

49. if (httpResponse.getStatusLine().getStatusCode() == 200) {

50. String strResult = EntityUtils.toString(httpResponse.getEntity());

51. mtv1.setText(strResult);

52. }

53. } catch (Exception e) {

54. // TODO: handle exception

55. e.printStackTrace();

56. }

57. }

58.

59. }

60. );

61.

62. mb2.setOnClickListener(new Button.OnClickListener() {

63.

64. public void onClick(View v) {

65. // TODO Auto-generated method stub

66. String uriAPI = "http://www.dubblogs.cc:8751/android/test/api/get/index.php?str=I+am+Get+String";

67. HttpGet httpRequest = new HttpGet(uriAPI);

68. try {

69. HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);

70. if (httpResponse.getStatusLine().getStatusCode() == 200) {

71. String strResult = EntityUtils.toString(httpResponse.getEntity());

72. strResult = eregi_replace("( || | )", "", strResult);

73. mtv1.setText(strResult);

74. }

75. } catch (Exception e) {

76. // TODO: handle exception

77. e.printStackTrace();

78. }

79. }

80.

81. }

82. );

83. }

84.

85. protected String eregi_replace(String strFrom, String strTo,

86. String strTarget) {

87. // TODO Auto-generated method stub

88. String strPattern = "(?!)" + strFrom;

上一页  1 2 3 4 5 6  下一页

Tags:Android HttpConnect

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接