android 通过HttpPost 调用.Net Wcf
16lz
2021-01-23
String uri = "http://192.168.24.117/ProductService.svc/GetArticleList"; DefaultHttpClient client=new DefaultHttpClient(); HttpPost requst=new HttpPost(uri); requst.setHeader("Accept", "application/json"); requst.addHeader("Content-Type", "application/json; charset=utf-8"); try {HttpResponse responsepost = client.execute(requst); if(responsepost.getStatusLine().getStatusCode()==200){ String response=EntityUtils.toString(responsepost.getEntity()); JSONObject jsonObject=new JSONObject(response); JSONArray arr = new JSONArray(jsonObject.getString("Data")); for(int i=0;i<arr.length();i++){ JSONObject item = (JSONObject) arr.get(i); Log.i(TAG,item.getString("Title")); } Log.i(TAG,jsonObject.getString("Data")); }} catch (ClientProtocolException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();}
btnArticle.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View arg0) {String uri = "http://192.168.24.117/AppService.svc/GetArticleDetails"; DefaultHttpClient client=new DefaultHttpClient(); HttpPost requst=new HttpPost(uri); requst.setHeader("Accept", "application/json"); requst.addHeader("Content-Type", "application/json; charset=utf-8"); JSONObject jsonParams=new JSONObject(); try { jsonParams.put("sysNo","1"); HttpEntity bodyEntity=new StringEntity(jsonParams.toString(),"utf8"); requst.setEntity(bodyEntity); HttpResponse responsepost = client.execute(requst); if(responsepost.getStatusLine().getStatusCode()==200){ String response=EntityUtils.toString(responsepost.getEntity()); JSONObject jsonObject=new JSONObject(response); JSONObject jsonData=new JSONObject(jsonObject.getString("Data")); //Log.i(TAG,response); //Log.i(TAG,jsonObject.getString("Data")); Log.i(TAG,"编号:"+jsonData.getString("SysNo") +" 标题:"+jsonData.getString("Title")); }} catch (ClientProtocolException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();}}});
<!--wcf begin--> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="ServiceProxyBinding" sendTimeout="00:10:00" receiveTimeout="00:10:00" closeTimeout="00:10:00" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" > <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> </binding> <binding name="LargeSettings" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> <security mode="None" /> </binding> <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> <security mode="None" /> </binding> </basicHttpBinding> <webHttpBinding> <binding maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> </binding> </webHttpBinding> </bindings> <!--services--> <services> <service name="Pisen.Service.Impl.ProductService" behaviorConfiguration="ProductServiceBehavior"> <endpoint address="" binding="webHttpBinding" contract="Pisen.Service.Contract.IProductService" behaviorConfiguration="web" /> </service> <service name="Pisen.Service.Impl.AppService" behaviorConfiguration="AppServiceBehavior"> <endpoint address="" binding="webHttpBinding" contract="Pisen.Service.Contract.IAppService" behaviorConfiguration="web" /> </service> </services> <!--behaviors--> <behaviors> <endpointBehaviors> <behavior name="web"> <webHttp helpEnabled="true" /> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="ProductServiceBehavior"> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> <behavior name="AppServiceBehavior"> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> <!--wcf end-->
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
更多相关文章
- android 去除 标题和状态栏
- 四极管:Android标题栏各种设置
- Android之自定义标题栏(组合控件)
- Android 去掉窗口标题和程序全屏
- Android NoTitle 不显示标题
- 自定义ActionBar标题与菜单中的文字样式
- Android中全屏或者取消标题栏