小猪的Android入门之路 Day 8 part 4

小猪的Android入门之路 Day 8 part 4

Android网络编程浅析——Android网络数据的上传

——转载请注明出处:coder-pig


本节引言:

在part 3中我们已经学习了Android网络数据的下载,难点是多线程断点续传下载;

有下载,当然也有上传啦,本节就来研究下Android中的网络数据的上传!

1.使用GET或者Post方式上传数据给服务器

2.使用开源框架HttpClient上传数据到服务区

3.发送xml数据给服务器

4.通过Http协议上传文件

5.WebService平台的了解以及简单应用

好了,开始本节的内容吧!



本节学习路线图


注意:在查询城市天气那个demo中可以不适用地区码,直接发送城市名即可!





正文:


使用GET方法或者POST方法上传数据



核心代码比较:


GET服务类:

<a target=_blank id="L1" href="http://blog.csdn.net/coder_pig/article/details/39381479#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;">  1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/coder_pig/article/details/39381479#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;">  2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/coder_pig/article/details/39381479#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;">  3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/coder_pig/article/details/39381479#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;">  4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/coder_pig/article/details/39381479#L5" rel="#L5" style="color: rgb(102, 102, 102); text-decoration: none;">  5</a>
<a target=_blank id="L6" href="http://blog.csdn.net/coder_pig/article/details/39381479#L6" rel="#L6" style="color: rgb(102, 102, 102); text-decoration: none;">  6</a>
<a target=_blank id="L7" href="http://blog.csdn.net/coder_pig/article/details/39381479#L7" rel="#L7" style="color: rgb(102, 102, 102); text-decoration: none;">  7</a>
<a target=_blank id="L8" href="http://blog.csdn.net/coder_pig/article/details/39381479#L8" rel="#L8" style="color: rgb(102, 102, 102); text-decoration: none;">  8</a>
<a target=_blank id="L9" href="http://blog.csdn.net/coder_pig/article/details/39381479#L9" rel="#L9" style="color: rgb(102, 102, 102); text-decoration: none;">  9</a>
<a target=_blank id="L10" href="http://blog.csdn.net/coder_pig/article/details/39381479#L10" rel="#L10" style="color: rgb(102, 102, 102); text-decoration: none;"> 10</a>
<a target=_blank id="L11" href="http://blog.csdn.net/coder_pig/article/details/39381479#L11" rel="#L11" style="color: rgb(102, 102, 102); text-decoration: none;"> 11</a>
<a target=_blank id="L12" href="http://blog.csdn.net/coder_pig/article/details/39381479#L12" rel="#L12" style="color: rgb(102, 102, 102); text-decoration: none;"> 12</a>
<a target=_blank id="L13" href="http://blog.csdn.net/coder_pig/article/details/39381479#L13" rel="#L13" style="color: rgb(102, 102, 102); text-decoration: none;"> 13</a>
<a target=_blank id="L14" href="http://blog.csdn.net/coder_pig/article/details/39381479#L14" rel="#L14" style="color: rgb(102, 102, 102); text-decoration: none;"> 14</a>
<a target=_blank id="L15" href="http://blog.csdn.net/coder_pig/article/details/39381479#L15" rel="#L15" style="color: rgb(102, 102, 102); text-decoration: none;"> 15</a>
<a target=_blank id="L16" href="http://blog.csdn.net/coder_pig/article/details/39381479#L16" rel="#L16" style="color: rgb(102, 102, 102); text-decoration: none;"> 16</a>
<a target=_blank id="L17" href="http://blog.csdn.net/coder_pig/article/details/39381479#L17" rel="#L17" style="color: rgb(102, 102, 102); text-decoration: none;"> 17</a>
<a target=_blank id="L18" href="http://blog.csdn.net/coder_pig/article/details/39381479#L18" rel="#L18" style="color: rgb(102, 102, 102); text-decoration: none;"> 18</a>
<a target=_blank id="L19" href="http://blog.csdn.net/coder_pig/article/details/39381479#L19" rel="#L19" style="color: rgb(102, 102, 102); text-decoration: none;"> 19</a>
<a target=_blank id="L20" href="http://blog.csdn.net/coder_pig/article/details/39381479#L20" rel="#L20" style="color: rgb(102, 102, 102); text-decoration: none;"> 20</a>
<a target=_blank id="L21" href="http://blog.csdn.net/coder_pig/article/details/39381479#L21" rel="#L21" style="color: rgb(102, 102, 102); text-decoration: none;"> 21</a>
<a target=_blank id="L22" href="http://blog.csdn.net/coder_pig/article/details/39381479#L22" rel="#L22" style="color: rgb(102, 102, 102); text-decoration: none;"> 22</a>
<a target=_blank id="L23" href="http://blog.csdn.net/coder_pig/article/details/39381479#L23" rel="#L23" style="color: rgb(102, 102, 102); text-decoration: none;"> 23</a>
<a target=_blank id="L24" href="http://blog.csdn.net/coder_pig/article/details/39381479#L24" rel="#L24" style="color: rgb(102, 102, 102); text-decoration: none;"> 24</a>
<a target=_blank id="L25" href="http://blog.csdn.net/coder_pig/article/details/39381479#L25" rel="#L25" style="color: rgb(102, 102, 102); text-decoration: none;"> 25</a>
<a target=_blank id="L26" href="http://blog.csdn.net/coder_pig/article/details/39381479#L26" rel="#L26" style="color: rgb(102, 102, 102); text-decoration: none;"> 26</a>
<a target=_blank id="L27" href="http://blog.csdn.net/coder_pig/article/details/39381479#L27" rel="#L27" style="color: rgb(102, 102, 102); text-decoration: none;"> 27</a>
<a target=_blank id="L28" href="http://blog.csdn.net/coder_pig/article/details/39381479#L28" rel="#L28" style="color: rgb(102, 102, 102); text-decoration: none;"> 28</a>
<a target=_blank id="L29" href="http://blog.csdn.net/coder_pig/article/details/39381479#L29" rel="#L29" style="color: rgb(102, 102, 102); text-decoration: none;"> 29</a>
<a target=_blank id="L30" href="http://blog.csdn.net/coder_pig/article/details/39381479#L30" rel="#L30" style="color: rgb(102, 102, 102); text-decoration: none;"> 30</a>
<a target=_blank id="L31" href="http://blog.csdn.net/coder_pig/article/details/39381479#L31" rel="#L31" style="color: rgb(102, 102, 102); text-decoration: none;"> 31</a>
<a target=_blank id="L32" href="http://blog.csdn.net/coder_pig/article/details/39381479#L32" rel="#L32" style="color: rgb(102, 102, 102); text-decoration: none;"> 32</a>
<a target=_blank id="L33" href="http://blog.csdn.net/coder_pig/article/details/39381479#L33" rel="#L33" style="color: rgb(102, 102, 102); text-decoration: none;"> 33</a>
<a target=_blank id="L34" href="http://blog.csdn.net/coder_pig/article/details/39381479#L34" rel="#L34" style="color: rgb(102, 102, 102); text-decoration: none;"> 34</a>
<a target=_blank id="L35" href="http://blog.csdn.net/coder_pig/article/details/39381479#L35" rel="#L35" style="color: rgb(102, 102, 102); text-decoration: none;"> 35</a>
<a target=_blank id="L36" href="http://blog.csdn.net/coder_pig/article/details/39381479#L36" rel="#L36" style="color: rgb(102, 102, 102); text-decoration: none;"> 36</a>
<a target=_blank id="L37" href="http://blog.csdn.net/coder_pig/article/details/39381479#L37" rel="#L37" style="color: rgb(102, 102, 102); text-decoration: none;"> 37</a>
<a target=_blank id="L38" href="http://blog.csdn.net/coder_pig/article/details/39381479#L38" rel="#L38" style="color: rgb(102, 102, 102); text-decoration: none;"> 38</a>
<a target=_blank id="L39" href="http://blog.csdn.net/coder_pig/article/details/39381479#L39" rel="#L39" style="color: rgb(102, 102, 102); text-decoration: none;"> 39</a>
<a target=_blank id="L40" href="http://blog.csdn.net/coder_pig/article/details/39381479#L40" rel="#L40" style="color: rgb(102, 102, 102); text-decoration: none;"> 40</a>
<a target=_blank id="L41" href="http://blog.csdn.net/coder_pig/article/details/39381479#L41" rel="#L41" style="color: rgb(102, 102, 102); text-decoration: none;"> 41</a>
<a target=_blank id="L42" href="http://blog.csdn.net/coder_pig/article/details/39381479#L42" rel="#L42" style="color: rgb(102, 102, 102); text-decoration: none;"> 42</a>
<a target=_blank id="L43" href="http://blog.csdn.net/coder_pig/article/details/39381479#L43" rel="#L43" style="color: rgb(102, 102, 102); text-decoration: none;"> 43</a>
<a target=_blank id="L44" href="http://blog.csdn.net/coder_pig/article/details/39381479#L44" rel="#L44" style="color: rgb(102, 102, 102); text-decoration: none;"> 44</a>
<a target=_blank id="L45" href="http://blog.csdn.net/coder_pig/article/details/39381479#L45" rel="#L45" style="color: rgb(102, 102, 102); text-decoration: none;"> 45</a>
<a target=_blank id="L46" href="http://blog.csdn.net/coder_pig/article/details/39381479#L46" rel="#L46" style="color: rgb(102, 102, 102); text-decoration: none;"> 46</a>
<a target=_blank id="L47" href="http://blog.csdn.net/coder_pig/article/details/39381479#L47" rel="#L47" style="color: rgb(102, 102, 102); text-decoration: none;"> 47</a>
<a target=_blank id="L48" href="http://blog.csdn.net/coder_pig/article/details/39381479#L48" rel="#L48" style="color: rgb(102, 102, 102); text-decoration: none;"> 48</a>
<a target=_blank id="L49" href="http://blog.csdn.net/coder_pig/article/details/39381479#L49" rel="#L49" style="color: rgb(102, 102, 102); text-decoration: none;"> 49</a>
<a target=_blank id="L50" href="http://blog.csdn.net/coder_pig/article/details/39381479#L50" rel="#L50" style="color: rgb(102, 102, 102); text-decoration: none;"> 50</a>
<a target=_blank id="L51" href="http://blog.csdn.net/coder_pig/article/details/39381479#L51" rel="#L51" style="color: rgb(102, 102, 102); text-decoration: none;"> 51</a>
<a target=_blank id="L52" href="http://blog.csdn.net/coder_pig/article/details/39381479#L52" rel="#L52" style="color: rgb(102, 102, 102); text-decoration: none;"> 52</a>
<a target=_blank id="L53" href="http://blog.csdn.net/coder_pig/article/details/39381479#L53" rel="#L53" style="color: rgb(102, 102, 102); text-decoration: none;"> 53</a>
<a target=_blank id="L54" href="http://blog.csdn.net/coder_pig/article/details/39381479#L54" rel="#L54" style="color: rgb(102, 102, 102); text-decoration: none;"> 54</a>
           
           
package com . example . service ;
import java.net.HttpURLConnection ;
import java.net.URL ;
import java.net.URLEncoder ;
import java.util.HashMap ;
import java.util.Map ;
import java.util.Map.Entry ;
import android.util.Log ;
public class GETService {
public static boolean save ( String name , String passwd ) throws Exception
{
String path = "http://10.13.20.73:8081/UploadWeb/ServletForGET" ;
Map < String , String > params = new HashMap < String , String >();
Log . e ( "逗比" , name + passwd );
params . put ( "name" , name );
params . put ( "passwd" , passwd );
return sendGetRequest ( path , params , "UTF-8" );
}
/**
* 发送GET请求
* @param path 请求路径
* @param params 请求参数
* */
private static boolean sendGetRequest ( String path ,
Map < String , String > params , String encoding ) throws Exception {
StringBuilder sb = new StringBuilder ( path );
if ( params != null && ! params . isEmpty ())
{
sb . append ( "?" );
for ( Entry < String , String > entry : params . entrySet ())
{
sb . append ( entry . getKey ()). append ( "=" );
sb . append ( URLEncoder . encode ( entry . getValue (), encoding ));
sb . append ( "&" );
}
sb . deleteCharAt ( sb . length () - 1 );
System . out . println ( sb . toString ());
}
HttpURLConnection conn = ( HttpURLConnection ) new URL ( sb . toString ()). openConnection ();
conn . setConnectTimeout ( 5000 );
conn . setRequestMethod ( "GET" );
if ( conn . getResponseCode () == 200 )
{
return true ;
}
return false ;
}
}
 来自CODE的代码片
GETService.java

POST服务类:

<a target=_blank id="L1" href="http://blog.csdn.net/coder_pig/article/details/39381479#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;">  1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/coder_pig/article/details/39381479#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;">  2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/coder_pig/article/details/39381479#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;">  3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/coder_pig/article/details/39381479#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;">  4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/coder_pig/article/details/39381479#L5" rel="#L5" style="color: rgb(102, 102, 102); text-decoration: none;">  5</a>
<a target=_blank id="L6" href="http://blog.csdn.net/coder_pig/article/details/39381479#L6" rel="#L6" style="color: rgb(102, 102, 102); text-decoration: none;">  6</a>
<a target=_blank id="L7" href="http://blog.csdn.net/coder_pig/article/details/39381479#L7" rel="#L7" style="color: rgb(102, 102, 102); text-decoration: none;">  7</a>
<a target=_blank id="L8" href="http://blog.csdn.net/coder_pig/article/details/39381479#L8" rel="#L8" style="color: rgb(102, 102, 102); text-decoration: none;">  8</a>
<a target=_blank id="L9" href="http://blog.csdn.net/coder_pig/article/details/39381479#L9" rel="#L9" style="color: rgb(102, 102, 102); text-decoration: none;">  9</a>
<a target=_blank id="L10" href="http://blog.csdn.net/coder_pig/article/details/39381479#L10" rel="#L10" style="color: rgb(102, 102, 102); text-decoration: none;"> 10</a>
<a target=_blank id="L11" href="http://blog.csdn.net/coder_pig/article/details/39381479#L11" rel="#L11" style="color: rgb(102, 102, 102); text-decoration: none;"> 11</a>
<a target=_blank id="L12" href="http://blog.csdn.net/coder_pig/article/details/39381479#L12" rel="#L12" style="color: rgb(102, 102, 102); text-decoration: none;"> 12</a>
<a target=_blank id="L13" href="http://blog.csdn.net/coder_pig/article/details/39381479#L13" rel="#L13" style="color: rgb(102, 102, 102); text-decoration: none;"> 13</a>
<a target=_blank id="L14" href="http://blog.csdn.net/coder_pig/article/details/39381479#L14" rel="#L14" style="color: rgb(102, 102, 102); text-decoration: none;"> 14</a>
<a target=_blank id="L15" href="http://blog.csdn.net/coder_pig/article/details/39381479#L15" rel="#L15" style="color: rgb(102, 102, 102); text-decoration: none;"> 15</a>
<a target=_blank id="L16" href="http://blog.csdn.net/coder_pig/article/details/39381479#L16" rel="#L16" style="color: rgb(102, 102, 102); text-decoration: none;"> 16</a>
<a target=_blank id="L17" href="http://blog.csdn.net/coder_pig/article/details/39381479#L17" rel="#L17" style="color: rgb(102, 102, 102); text-decoration: none;"> 17</a>
<a target=_blank id="L18" href="http://blog.csdn.net/coder_pig/article/details/39381479#L18" rel="#L18" style="color: rgb(102, 102, 102); text-decoration: none;"> 18</a>
<a target=_blank id="L19" href="http://blog.csdn.net/coder_pig/article/details/39381479#L19" rel="#L19" style="color: rgb(102, 102, 102); text-decoration: none;"> 19</a>
<a target=_blank id="L20" href="http://blog.csdn.net/coder_pig/article/details/39381479#L20" rel="#L20" style="color: rgb(102, 102, 102); text-decoration: none;"> 20</a>
<a target=_blank id="L21" href="http://blog.csdn.net/coder_pig/article/details/39381479#L21" rel="#L21" style="color: rgb(102, 102, 102); text-decoration: none;"> 21</a>
<a target=_blank id="L22" href="http://blog.csdn.net/coder_pig/article/details/39381479#L22" rel="#L22" style="color: rgb(102, 102, 102); text-decoration: none;"> 22</a>
<a target=_blank id="L23" href="http://blog.csdn.net/coder_pig/article/details/39381479#L23" rel="#L23" style="color: rgb(102, 102, 102); text-decoration: none;"> 23</a>
<a target=_blank id="L24" href="http://blog.csdn.net/coder_pig/article/details/39381479#L24" rel="#L24" style="color: rgb(102, 102, 102); text-decoration: none;"> 24</a>
<a target=_blank id="L25" href="http://blog.csdn.net/coder_pig/article/details/39381479#L25" rel="#L25" style="color: rgb(102, 102, 102); text-decoration: none;"> 25</a>
<a target=_blank id="L26" href="http://blog.csdn.net/coder_pig/article/details/39381479#L26" rel="#L26" style="color: rgb(102, 102, 102); text-decoration: none;"> 26</a>
<a target=_blank id="L27" href="http://blog.csdn.net/coder_pig/article/details/39381479#L27" rel="#L27" style="color: rgb(102, 102, 102); text-decoration: none;"> 27</a>
<a target=_blank id="L28" href="http://blog.csdn.net/coder_pig/article/details/39381479#L28" rel="#L28" style="color: rgb(102, 102, 102); text-decoration: none;"> 28</a>
<a target=_blank id="L29" href="http://blog.csdn.net/coder_pig/article/details/39381479#L29" rel="#L29" style="color: rgb(102, 102, 102); text-decoration: none;"> 29</a>
<a target=_blank id="L30" href="http://blog.csdn.net/coder_pig/article/details/39381479#L30" rel="#L30" style="color: rgb(102, 102, 102); text-decoration: none;"> 30</a>
<a target=_blank id="L31" href="http://blog.csdn.net/coder_pig/article/details/39381479#L31" rel="#L31" style="color: rgb(102, 102, 102); text-decoration: none;"> 31</a>
<a target=_blank id="L32" href="http://blog.csdn.net/coder_pig/article/details/39381479#L32" rel="#L32" style="color: rgb(102, 102, 102); text-decoration: none;"> 32</a>
<a target=_blank id="L33" href="http://blog.csdn.net/coder_pig/article/details/39381479#L33" rel="#L33" style="color: rgb(102, 102, 102); text-decoration: none;"> 33</a>
<a target=_blank id="L34" href="http://blog.csdn.net/coder_pig/article/details/39381479#L34" rel="#L34" style="color: rgb(102, 102, 102); text-decoration: none;"> 34</a>
<a target=_blank id="L35" href="http://blog.csdn.net/coder_pig/article/details/39381479#L35" rel="#L35" style="color: rgb(102, 102, 102); text-decoration: none;"> 35</a>
<a target=_blank id="L36" href="http://blog.csdn.net/coder_pig/article/details/39381479#L36" rel="#L36" style="color: rgb(102, 102, 102); text-decoration: none;"> 36</a>
<a target=_blank id="L37" href="http://blog.csdn.net/coder_pig/article/details/39381479#L37" rel="#L37" style="color: rgb(102, 102, 102); text-decoration: none;"> 37</a>
<a target=_blank id="L38" href="http://blog.csdn.net/coder_pig/article/details/39381479#L38" rel="#L38" style="color: rgb(102, 102, 102); text-decoration: none;"> 38</a>
<a target=_blank id="L39" href="http://blog.csdn.net/coder_pig/article/details/39381479#L39" rel="#L39" style="color: rgb(102, 102, 102); text-decoration: none;"> 39</a>
<a target=_blank id="L40" href="http://blog.csdn.net/coder_pig/article/details/39381479#L40" rel="#L40" style="color: rgb(102, 102, 102); text-decoration: none;"> 40</a>
<a target=_blank id="L41" href="http://blog.csdn.net/coder_pig/article/details/39381479#L41" rel="#L41" style="color: rgb(102, 102, 102); text-decoration: none;"> 41</a>
<a target=_blank id="L42" href="http://blog.csdn.net/coder_pig/article/details/39381479#L42" rel="#L42" style="color: rgb(102, 102, 102); text-decoration: none;"> 42</a>
<a target=_blank id="L43" href="http://blog.csdn.net/coder_pig/article/details/39381479#L43" rel="#L43" style="color: rgb(102, 102, 102); text-decoration: none;"> 43</a>
<a target=_blank id="L44" href="http://blog.csdn.net/coder_pig/article/details/39381479#L44" rel="#L44" style="color: rgb(102, 102, 102); text-decoration: none;"> 44</a>
<a target=_blank id="L45" href="http://blog.csdn.net/coder_pig/article/details/39381479#L45" rel="#L45" style="color: rgb(102, 102, 102); text-decoration: none;"> 45</a>
<a target=_blank id="L46" href="http://blog.csdn.net/coder_pig/article/details/39381479#L46" rel="#L46" style="color: rgb(102, 102, 102); text-decoration: none;"> 46</a>
<a target=_blank id="L47" href="http://blog.csdn.net/coder_pig/article/details/39381479#L47" rel="#L47" style="color: rgb(102, 102, 102); text-decoration: none;"> 47</a>
<a target=_blank id="L48" href="http://blog.csdn.net/coder_pig/article/details/39381479#L48" rel="#L48" style="color: rgb(102, 102, 102); text-decoration: none;"> 48</a>
<a target=_blank id="L49" href="http://blog.csdn.net/coder_pig/article/details/39381479#L49" rel="#L49" style="color: rgb(102, 102, 102); text-decoration: none;"> 49</a>
<a target=_blank id="L50" href="http://blog.csdn.net/coder_pig/article/details/39381479#L50" rel="#L50" style="color: rgb(102, 102, 102); text-decoration: none;"> 50</a>
<a target=_blank id="L51" href="http://blog.csdn.net/coder_pig/article/details/39381479#L51" rel="#L51" style="color: rgb(102, 102, 102); text-decoration: none;"> 51</a>
<a target=_blank id="L52" href="http://blog.csdn.net/coder_pig/article/details/39381479#L52" rel="#L52" style="color: rgb(102, 102, 102); text-decoration: none;"> 52</a>
<a target=_blank id="L53" href="http://blog.csdn.net/coder_pig/article/details/39381479#L53" rel="#L53" style="color: rgb(102, 102, 102); text-decoration: none;"> 53</a>
<a target=_blank id="L54" href="http://blog.csdn.net/coder_pig/article/details/39381479#L54" rel="#L54" style="color: rgb(102, 102, 102); text-decoration: none;"> 54</a>
<a target=_blank id="L55" href="http://blog.csdn.net/coder_pig/article/details/39381479#L55" rel="#L55" style="color: rgb(102, 102, 102); text-decoration: none;"> 55</a>
<a target=_blank id="L56" href="http://blog.csdn.net/coder_pig/article/details/39381479#L56" rel="#L56" style="color: rgb(102, 102, 102); text-decoration: none;"> 56</a>
<a target=_blank id="L57" href="http://blog.csdn.net/coder_pig/article/details/39381479#L57" rel="#L57" style="color: rgb(102, 102, 102); text-decoration: none;"> 57</a>
<a target=_blank id="L58" href="http://blog.csdn.net/coder_pig/article/details/39381479#L58" rel="#L58" style="color: rgb(102, 102, 102); text-decoration: none;"> 58</a>
<a target=_blank id="L59" href="http://blog.csdn.net/coder_pig/article/details/39381479#L59" rel="#L59" style="color: rgb(102, 102, 102); text-decoration: none;"> 59</a>
<a target=_blank id="L60" href="http://blog.csdn.net/coder_pig/article/details/39381479#L60" rel="#L60" style="color: rgb(102, 102, 102); text-decoration: none;"> 60</a>
<a target=_blank id="L61" href="http://blog.csdn.net/coder_pig/article/details/39381479#L61" rel="#L61" style="color: rgb(102, 102, 102); text-decoration: none;"> 61</a>
           
           
package com . example . service ;
import java.io.OutputStream ;
import java.net.HttpURLConnection ;
import java.net.URL ;
import java.net.URLEncoder ;
import java.util.HashMap ;
import java.util.Map ;
import java.util.Map.Entry ;
public class POSTService {
public static boolean save ( String name , String passwd ) throws Exception
{
String path = "http://10.13.20.73:8081/UploadWeb/ServletForPOST" ;
Map < String , String > params = new HashMap < String , String >();
params . put ( "name" , name );
params . put ( "passwd" , passwd );
return sendPOSTRequest ( path , params , "UTF-8" );
}
/**
* 发送POST请求
* @param path 请求路径
* @param params 请求参数
* */
private static boolean sendPOSTRequest ( String path ,
Map < String , String > params , String encoding ) throws Exception {
StringBuilder sb = new StringBuilder ( path );
if ( params != null && ! params . isEmpty ())
{
sb . append ( "?" );
for ( Entry < String , String > entry : params . entrySet ())
{
sb . append ( entry . getKey ()). append ( "=" );
sb . append ( URLEncoder . encode ( entry . getValue (), encoding ));
sb . append ( "&" );
}
sb . deleteCharAt ( sb . length () - 1 );
System . out . println ( sb . toString ());
}
byte [] data = sb . toString (). getBytes ();
HttpURLConnection conn = ( HttpURLConnection ) new URL ( sb . toString ()). openConnection ();
conn . setConnectTimeout ( 5000 );
conn . setRequestMethod ( "POST" );
conn . setDoOutput ( true ); //设置允许对外传输数据
conn . setRequestProperty ( "Content-Type" , "application/" +
"x-www-form-urlencoded" );
conn . setRequestProperty ( "Content-Length" , data . length + "" );
OutputStream os = conn . getOutputStream ();
os . write ( data );
os . flush ();
if ( conn . getResponseCode () == 200 )
{
return true ;
}
return false ;
}
}
 来自CODE的代码片
POSTService.java

ps:相信细心的朋友都看出来这两个服务类不同的地方了,get是直接发送请求的,而post还需要设置相关的参数,

最后是以流的方式提交数据的!

完整项目下载:http://pan.baidu.com/s/1qWobnvm

效果图:



ps:另外还要说一点的是,传递中文可能出现乱码的情况,笔者之前也在这里纠结了半天,改来改去还是不行,后来发现是自己

的myeclpise的问题,上述运行结果是到同学的电脑运行的结果,乱码的话是因为tomcat默认支持的事iso8859-1编码方式

下面提供两个简单的解决乱码问题的方法(其实更重要的是注意编码的统一!!!)

1.在servlet取出数据的时候,使用下述代码进行转码:

 String name = new String(request.getParameter("name").getBytes("iso-8859-1"),"UTF-8"); 
2.修改Tomcat的conf/server.xml文件,找到,下述代码,添加:URIEncoding='UTF-8'

修改后:(utf-8不行的话再改成gbk试试)


ps:如上述方法都不行的话,就可能是tomcat的问题了,建议别直接使用myeclpise提供的tomcat;自己下载个tomcat配置下

如果还是乱码;去别人电脑试试,如果可以就说明是编译器的问题了;如果还是不行的话,我也帮不了你了委屈









使用开源框架HttpClient发送请求:




核心代码:(直接使用httpClient发送post请求)

<a target=_blank id="L1" href="http://blog.csdn.net/coder_pig/article/details/39381479#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;">  1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/coder_pig/article/details/39381479#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;">  2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/coder_pig/article/details/39381479#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;">  3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/coder_pig/article/details/39381479#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;">  4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/coder_pig/article/details/39381479#L5" rel="#L5" style="color: rgb(102, 102, 102); text-decoration: none;">  5</a>
<a target=_blank id="L6" href="http://blog.csdn.net/coder_pig/article/details/39381479#L6" rel="#L6" style="color: rgb(102, 102, 102); text-decoration: none;">  6</a>
<a target=_blank id="L7" href="http://blog.csdn.net/coder_pig/article/details/39381479#L7" rel="#L7" style="color: rgb(102, 102, 102); text-decoration: none;">  7</a>
<a target=_blank id="L8" href="http://blog.csdn.net/coder_pig/article/details/39381479#L8" rel="#L8" style="color: rgb(102, 102, 102); text-decoration: none;">  8</a>
<a target=_blank id="L9" href="http://blog.csdn.net/coder_pig/article/details/39381479#L9" rel="#L9" style="color: rgb(102, 102, 102); text-decoration: none;">  9</a>
<a target=_blank id="L10" href="http://blog.csdn.net/coder_pig/article/details/39381479#L10" rel="#L10" style="color: rgb(102, 102, 102); text-decoration: none;"> 10</a>
<a target=_blank id="L11" href="http://blog.csdn.net/coder_pig/article/details/39381479#L11" rel="#L11" style="color: rgb(102, 102, 102); text-decoration: none;"> 11</a>
<a target=_blank id="L12" href="http://blog.csdn.net/coder_pig/article/details/39381479#L12" rel="#L12" style="color: rgb(102, 102, 102); text-decoration: none;"> 12</a>
<a target=_blank id="L13" href="http://blog.csdn.net/coder_pig/article/details/39381479#L13" rel="#L13" style="color: rgb(102, 102, 102); text-decoration: none;"> 13</a>
<a target=_blank id="L14" href="http://blog.csdn.net/coder_pig/article/details/39381479#L14" rel="#L14" style="color: rgb(102, 102, 102); text-decoration: none;"> 14</a>
<a target=_blank id="L15" href="http://blog.csdn.net/coder_pig/article/details/39381479#L15" rel="#L15" style="color: rgb(102, 102, 102); text-decoration: none;"> 15</a>
<a target=_blank id="L16" href="http://blog.csdn.net/coder_pig/article/details/39381479#L16" rel="#L16" style="color: rgb(102, 102, 102); text-decoration: none;"> 16</a>
<a target=_blank id="L17" href="http://blog.csdn.net/coder_pig/article/details/39381479#L17" rel="#L17" style="color: rgb(102, 102, 102); text-decoration: none;"> 17</a>
<a target=_blank id="L18" href="http://blog.csdn.net/coder_pig/article/details/39381479#L18" rel="#L18" style="color: rgb(102, 102, 102); text-decoration: none;"> 18</a>
<a target=_blank id="L19" href="http://blog.csdn.net/coder_pig/article/details/39381479#L19" rel="#L19" style="color: rgb(102, 102, 102); text-decoration: none;"> 19</a>
<a target=_blank id="L20" href="http://blog.csdn.net/coder_pig/article/details/39381479#L20" rel="#L20" style="color: rgb(102, 102, 102); text-decoration: none;"> 20</a>
<a target=_blank id="L21" href="http://blog.csdn.net/coder_pig/article/details/39381479#L21" rel="#L21" style="color: rgb(102, 102, 102); text-decoration: none;"> 21</a>
<a target=_blank id="L22" href="http://blog.csdn.net/coder_pig/article/details/39381479#L22" rel="#L22" style="color: rgb(102, 102, 102); text-decoration: none;"> 22</a>
<a target=_blank id="L23" href="http://blog.csdn.net/coder_pig/article/details/39381479#L23" rel="#L23" style="color: rgb(102, 102, 102); text-decoration: none;"> 23</a>
<a target=_blank id="L24" href="http://blog.csdn.net/coder_pig/article/details/39381479#L24" rel="#L24" style="color: rgb(102, 102, 102); text-decoration: none;"> 24</a>
           
           
private static boolean HttpClientSendPostRequest ( String path , Map < String , String >
params , String encoding ) throws Exception
{
//NameValuePair是HttpClient提供的一个类,用于提交表单数据
List < NameValuePair > pairs = new ArrayList < NameValuePair >();
if ( params != null && ! params . isEmpty ())
{
for ( Map . Entry < String , String > entry: params . entrySet ())
{
pairs . add ( new BasicNameValuePair ( entry . getKey (), entry . getValue ()));
}
}
UrlEncodedFormEntity entity = new UrlEncodedFormEntity ( pairs , encoding );
HttpPost post = new HttpPost ( path );
post . setEntity ( entity );
DefaultHttpClient client = new DefaultHttpClient ();
HttpResponse response = client . execute ( post );
if ( response . getStatusLine (). getStatusCode () == 200 )
{
return true ;
}
return false ;
}
 来自CODE的代码片
HttpClientPostService.java

代码使用示例:

用户向某个jsp页面发送请求,如果没登陆的话返回提示没有没有权限访问页面;

点击登录后,验证账号密码是否正确,正确的话弹出Toast信息,并显示服务端反馈的内容

服务端使用到了session,相信学过jsp的同学都知道,可以通过这个判断用户是否为登录状态!

这里就直接套用疯狂讲义中的demo

效果图:


代码下载:http://pan.baidu.com/s/1kTgJRxX

核心代码解析:

①服务端如何判断用户是否登录?

答:点击登录按钮指向的是login.jsp,在这里完成登录,同时把状态写入到session

session.setAttribute("user" , name);

同时在该页面中匹配账号密码是否正确,否则返回不同的结果,成功或者失败!

当我们点击访问页面,请求指向的事secret.jsp页面,该页面先取出session中的name对应的值

与"jay"进行匹配,有的话,根据判断结果返回不同的处理结果:

<%Object user = session.getAttribute("user");

if(user != null && user.toString().trim().equals("jay"))....%>

else{out.println("您没有被授权访问该页面");}%>

②客户端提交请求,解析响应结果:

[java]   view plain copy print ?
  1. // 创建一个HttpGet对象  
  2.     HttpGet get = new HttpGet("http://10.13.20.32:8080/foo/secret.jsp");  
  3.   
  4. // 发送GET请求  
  5. HttpResponse httpResponse = httpClient.execute(get);  
  6. //获得服务器反馈的结果  
  7. HttpEntity entity = httpResponse.getEntity();  
  8. if (entity != null)  
  9. {  
  10.     // 读取服务器响应  
  11.     BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));  
  12.     String line = null;  
  13.     while ((line = br.readLine()) != null)  
  14.         {  
  15.             Message msg = new Message();  
  16.             msg.what = 0x123;  
  17.             msg.obj = line;  
  18.             handler.sendMessage(msg);  
  19.     }  




发送xml数据给服务器:

和前面的差不多,这里只贴核心业务代码,要用的时候直接复制即可!


<a target=_blank id="L1" href="http://blog.csdn.net/coder_pig/article/details/39381479#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;">  1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/coder_pig/article/details/39381479#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;">  2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/coder_pig/article/details/39381479#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;">  3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/coder_pig/article/details/39381479#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;">  4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/coder_pig/article/details/39381479#L5" rel="#L5" style="color: rgb(102, 102, 102); text-decoration: none;">  5</a>
<a target=_blank id="L6" href="http://blog.csdn.net/coder_pig/article/details/39381479#L6" rel="#L6" style="color: rgb(102, 102, 102); text-decoration: none;">  6</a>
<a target=_blank id="L7" href="http://blog.csdn.net/coder_pig/article/details/39381479#L7" rel="#L7" style="color: rgb(102, 102, 102); text-decoration: none;">  7</a>
<a target=_blank id="L8" href="http://blog.csdn.net/coder_pig/article/details/39381479#L8" rel="#L8" style="color: rgb(102, 102, 102); text-decoration: none;">  8</a>
<a target=_blank id="L9" href="http://blog.csdn.net/coder_pig/article/details/39381479#L9" rel="#L9" style="color: rgb(102, 102, 102); text-decoration: none;">  9</a>
<a target=_blank id="L10" href="http://blog.csdn.net/coder_pig/article/details/39381479#L10" rel="#L10" style="color: rgb(102, 102, 102); text-decoration: none;"> 10</a>
<a target=_blank id="L11" href="http://blog.csdn.net/coder_pig/article/details/39381479#L11" rel="#L11" style="color: rgb(102, 102, 102); text-decoration: none;"> 11</a>
<a target=_blank id="L12" href="http://blog.csdn.net/coder_pig/article/details/39381479#L12" rel="#L12" style="color: rgb(102, 102, 102); text-decoration: none;"> 12</a>
<a target=_blank id="L13" href="http://blog.csdn.net/coder_pig/article/details/39381479#L13" rel="#L13" style="color: rgb(102, 102, 102); text-decoration: none;"> 13</a>
<a target=_blank id="L14" href="http://blog.csdn.net/coder_pig/article/details/39381479#L14" rel="#L14" style="color: rgb(102, 102, 102); text-decoration: none;"> 14</a>
<a target=_blank id="L15" href="http://blog.csdn.net/coder_pig/article/details/39381479#L15" rel="#L15" style="color: rgb(102, 102, 102); text-decoration: none;"> 15</a>
<a target=_blank id="L16" href="http://blog.csdn.net/coder_pig/article/details/39381479#L16" rel="#L16" style="color: rgb(102, 102, 102); text-decoration: none;"> 16</a>
<a target=_blank id="L17" href="http://blog.csdn.net/coder_pig/article/details/39381479#L17" rel="#L17" style="color: rgb(102, 102, 102); text-decoration: none;"> 17</a>
<a target=_blank id="L18" href="http://blog.csdn.net/coder_pig/article/details/39381479#L18" rel="#L18" style="color: rgb(102, 102, 102); text-decoration: none;"> 18</a>
<a target=_blank id="L19" href="http://blog.csdn.net/coder_pig/article/details/39381479#L19" rel="#L19" style="color: rgb(102, 102, 102); text-decoration: none;"> 19</a>
<a target=_blank id="L20" href="http://blog.csdn.net/coder_pig/article/details/39381479#L20" rel="#L20" style="color: rgb(102, 102, 102); text-decoration: none;"> 20</a>
<a target=_blank id="L21" href="http://blog.csdn.net/coder_pig/article/details/39381479#L21" rel="#L21" style="color: rgb(102, 102, 102); text-decoration: none;"> 21</a>
<a target=_blank id="L22" href="http://blog.csdn.net/coder_pig/article/details/39381479#L22" rel="#L22" style="color: rgb(102, 102, 102); text-decoration: none;"> 22</a>
<a target=_blank id="L23" href="http://blog.csdn.net/coder_pig/article/details/39381479#L23" rel="#L23" style="color: rgb(102, 102, 102); text-decoration: none;"> 23</a>
<a target=_blank id="L24" href="http://blog.csdn.net/coder_pig/article/details/39381479#L24" rel="#L24" style="color: rgb(102, 102, 102); text-decoration: none;"> 24</a>
<a target=_blank id="L25" href="http://blog.csdn.net/coder_pig/article/details/39381479#L25" rel="#L25" style="color: rgb(102, 102, 102); text-decoration: none;"> 25</a>
<a target=_blank id="L26" href="http://blog.csdn.net/coder_pig/article/details/39381479#L26" rel="#L26" style="color: rgb(102, 102, 102); text-decoration: none;"> 26</a>
<a target=_blank id="L27" href="http://blog.csdn.net/coder_pig/article/details/39381479#L27" rel="#L27" style="color: rgb(102, 102, 102); text-decoration: none;"> 27</a>
<a target=_blank id="L28" href="http://blog.csdn.net/coder_pig/article/details/39381479#L28" rel="#L28" style="color: rgb(102, 102, 102); text-decoration: none;"> 28</a>
<a target=_blank id="L29" href="http://blog.csdn.net/coder_pig/article/details/39381479#L29" rel="#L29" style="color: rgb(102, 102, 102); text-decoration: none;"> 29</a>
           
           
//发送xml的核心方法
public static boolean sendXML ( String path , String xml ) throws Exception
{
byte [] data = xml . getBytes ();
URL url = new URL ( path );
HttpURLConnection conn = ( HttpURLConnection ) url . openConnection ();
conn . setRequestMethod ( "POST" );
conn . setConnectTimeout ( 5000 );
conn . setDoOutput ( true ); //使用post提交数据,需要设置该参数允许对外输出
//关键:设置发送de内容的类型是XML格式的
conn . setRequestProperty ( "Content-Type" , "text/xml;charset=UTF-8" );
conn . setRequestProperty ( "Content-Length" , String . valueOf ( data . length ));
OutputStream os = conn . getOutputStream ();
os . write ( data );
os . flush ();
os . close ();
if ( conn . getResponseCode () == 200 ) return true ;
return false ;
}
//演示客户端发送xml示例
public void testSendXml () throws Throwable
{
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<persons><persion id=\"23\"><name>逗比</name><age>18</age>" +
"</person></persons>" ;
HttpRequest . sendXML ( "http://...." , xml );
}
 来自CODE的代码片
SendXML.java






使用Http协议完成文件上传操作:

相信大家在使用app的时候,都要完成一个注册用户的流程,而注册的时候,通常都是需要

用户上传图片作为自己的用户头像的,这里提供一个使用Http协议完成文件上传的业务代码:

另外,一般使用http上传的文件比较小,通常是小于2M的!

<a target=_blank id="L1" href="http://blog.csdn.net/coder_pig/article/details/39381479#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;">   1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/coder_pig/article/details/39381479#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;">   2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/coder_pig/article/details/39381479#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;">   3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/coder_pig/article/details/39381479#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;">   4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/coder_pig/article/details/39381479#L5" rel="#L5" style="color: rgb(102, 102, 102); text-decoration: none;">   5</a>
<a target=_blank id="L6" href="http://blog.csdn.net/coder_pig/article/details/39381479#L6" rel="#L6" style="color: rgb(102, 102, 102); text-decoration: none;">   6</a>
<a target=_blank id="L7" href="http://blog.csdn.net/coder_pig/article/details/39381479#L7" rel="#L7" style="color: rgb(102, 102, 102); text-decoration: none;">   7</a>
<a target=_blank id="L8" href="http://blog.csdn.net/coder_pig/article/details/39381479#L8" rel="#L8" style="color: rgb(102, 102, 102); text-decoration: none;">   8</a>
<a target=_blank id="L9" href="http://blog.csdn.net/coder_pig/article/details/39381479#L9" rel="#L9" style="color: rgb(102, 102, 102); text-decoration: none;">   9</a>
<a target=_blank id="L10" href="http://blog.csdn.net/coder_pig/article/details/39381479#L10" rel="#L10" style="color: rgb(102, 102, 102); text-decoration: none;">  10</a>
<a target=_blank id="L11" href="http://blog.csdn.net/coder_pig/article/details/39381479#L11" rel="#L11" style="color: rgb(102, 102, 102); text-decoration: none;">  11</a>
<a target=_blank id="L12" href="http://blog.csdn.net/coder_pig/article/details/39381479#L12" rel="#L12" style="color: rgb(102, 102, 102); text-decoration: none;">  12</a>
<a target=_blank id="L13" href="http://blog.csdn.net/coder_pig/article/details/39381479#L13" rel="#L13" style="color: rgb(102, 102, 102); text-decoration: none;">  13</a>
<a target=_blank id="L14" href="http://blog.csdn.net/coder_pig/article/details/39381479#L14" rel="#L14" style="color: rgb(102, 102, 102); text-decoration: none;">  14</a>
<a target=_blank id="L15" href="http://blog.csdn.net/coder_pig/article/details/39381479#L15" rel="#L15" style="color: rgb(102, 102, 102); text-decoration: none;">  15</a>
<a target=_blank id="L16" href="http://blog.csdn.net/coder_pig/article/details/39381479#L16" rel="#L16" style="color: rgb(102, 102, 102); text-decoration: none;">  16</a>
<a target=_blank id="L17" href="http://blog.csdn.net/coder_pig/article/details/39381479#L17" rel="#L17" style="color: rgb(102, 102, 102); text-decoration: none;">  17</a>
<a target=_blank id="L18" href="http://blog.csdn.net/coder_pig/article/details/39381479#L18" rel="#L18" style="color: rgb(102, 102, 102); text-decoration: none;">  18</a>
<a target=_blank id="L19" href="http://blog.csdn.net/coder_pig/article/details/39381479#L19" rel="#L19" style="color: rgb(102, 102, 102); text-decoration: none;">  19</a>
<a target=_blank id="L20" href="http://blog.csdn.net/coder_pig/article/details/39381479#L20" rel="#L20" style="color: rgb(102, 102, 102); text-decoration: none;">  20</a>
<a target=_blank id="L21" href="http://blog.csdn.net/coder_pig/article/details/39381479#L21" rel="#L21" style="color: rgb(102, 102, 102); text-decoration: none;">  21</a>
<a target=_blank id="L22" href="http://blog.csdn.net/coder_pig/article/details/39381479#L22" rel="#L22" style="color: rgb(102, 102, 102); text-decoration: none;">  22</a>
<a target=_blank id="L23" href="http://blog.csdn.net/coder_pig/article/details/39381479#L23" rel="#L23" style="color: rgb(102, 102, 102); text-decoration: none;">  23</a>
<a target=_blank id="L24" href="http://blog.csdn.net/coder_pig/article/details/39381479#L24" rel="#L24" style="color: rgb(102, 102, 102); text-decoration: none;">  24</a>
<a target=_blank id="L25" href="http://blog.csdn.net/coder_pig/article/details/39381479#L25" rel="#L25" style="color: rgb(102, 102, 102); text-decoration: none;">  25</a>
<a target=_blank id="L26" href="http://blog.csdn.net/coder_pig/article/details/39381479#L26" rel="#L26" style="color: rgb(102, 102, 102); text-decoration: none;">  26</a>
<a target=_blank id="L27" href="http://blog.csdn.net/coder_pig/article/details/39381479#L27" rel="#L27" style="color: rgb(102, 102, 102); text-decoration: none;">  27</a>
<a target=_blank id="L28" href="http://blog.csdn.net/coder_pig/article/details/39381479#L28" rel="#L28" style="color: rgb(102, 102, 102); text-decoration: none;">  28</a>
<a target=_blank id="L29" href="http://blog.csdn.net/coder_pig/article/details/39381479#L29" rel="#L29" style="color: rgb(102, 102, 102); text-decoration: none;">  29</a>
<a target=_blank id="L30" href="http://blog.csdn.net/coder_pig/article/details/39381479#L30" rel="#L30" style="color: rgb(102, 102, 102); text-decoration: none;">  30</a>
<a target=_blank id="L31" href="http://blog.csdn.net/coder_pig/article/details/39381479#L31" rel="#L31" style="color: rgb(102, 102, 102); text-decoration: none;">  31</a>
<a target=_blank id="L32" href="http://blog.csdn.net/coder_pig/article/details/39381479#L32" rel="#L32" style="color: rgb(102, 102, 102); text-decoration: none;">  32</a>
<a target=_blank id="L33" href="http://blog.csdn.net/coder_pig/article/details/39381479#L33" rel="#L33" style="color: rgb(102, 102, 102); text-decoration: none;">  33</a>
<a target=_blank id="L34" href="http://blog.csdn.net/coder_pig/article/details/39381479#L34" rel="#L34" style="color: rgb(102, 102, 102); text-decoration: none;">  34</a>
<a target=_blank id="L35" href="http://blog.csdn.net/coder_pig/article/details/39381479#L35" rel="#L35" style="color: rgb(102, 102, 102); text-decoration: none;">  35</a>
<a target=_blank id="L36" href="http://blog.csdn.net/coder_pig/article/details/39381479#L36" rel="#L36" style="color: rgb(102, 102, 102); text-decoration: none;">  36</a>
<a target=_blank id="L37" href="http://blog.csdn.net/coder_pig/article/details/39381479#L37" rel="#L37" style="color: rgb(102, 102, 102); text-decoration: none;">  37</a>
<a target=_blank id="L38" href="http://blog.csdn.net/coder_pig/article/details/39381479#L38" rel="#L38" style="color: rgb(102, 102, 102); text-decoration: none;">  38</a>
<a target=_blank id="L39" href="http://blog.csdn.net/coder_pig/article/details/39381479#L39" rel="#L39" style="color: rgb(102, 102, 102); text-decoration: none;">  39</a>
<a target=_blank id="L40" href="http://blog.csdn.net/coder_pig/article/details/39381479#L40" rel="#L40" style="color: rgb(102, 102, 102); text-decoration: none;">  40</a>
<a target=_blank id="L41" href="http://blog.csdn.net/coder_pig/article/details/39381479#L41" rel="#L41" style="color: rgb(102, 102, 102); text-decoration: none;">  41</a>
<a target=_blank id="L42" href="http://blog.csdn.net/coder_pig/article/details/39381479#L42" rel="#L42" style="color: rgb(102, 102, 102); text-decoration: none;">  42</a>
<a target=_blank id="L43" href="http://blog.csdn.net/coder_pig/article/details/39381479#L43" rel="#L43" style="color: rgb(102, 102, 102); text-decoration: none;">  43</a>
<a target=_blank id="L44" href="http://blog.csdn.net/coder_pig/article/details/39381479#L44" rel="#L44" style="color: rgb(102, 102, 102); text-decoration: none;">  44</a>
<a target=_blank id="L45" href="http://blog.csdn.net/coder_pig/article/details/39381479#L45" rel="#L45" style="color: rgb(102, 102, 102); text-decoration: none;">  45</a>
<a target=_blank id="L46" href="http://blog.csdn.net/coder_pig/article/details/39381479#L46" rel="#L46" style="color: rgb(102, 102, 102); text-decoration: none;">  46</a>
<a target=_blank id="L47" href="http://blog.csdn.net/coder_pig/article/details/39381479#L47" rel="#L47" style="color: rgb(102, 102, 102); text-decoration: none;">  47</a>
<a target=_blank id="L48" href="http://blog.csdn.net/coder_pig/article/details/39381479#L48" rel="#L48" style="color: rgb(102, 102, 102); text-decoration: none;">  48</a>
<a target=_blank id="L49" href="http://blog.csdn.net/coder_pig/article/details/39381479#L49" rel="#L49" style="color: rgb(102, 102, 102); text-decoration: none;">  49</a>
<a target=_blank id="L50" href="http://blog.csdn.net/coder_pig/article/details/39381479#L50" rel="#L50" style="color: rgb(102, 102, 102); text-decoration: none;">  50</a>
<a target=_blank id="L51" href="http://blog.csdn.net/coder_pig/article/details/39381479#L51" rel="#L51" style="color: rgb(102, 102, 102); text-decoration: none;">  51</a>
<a target=_blank id="L52" href="http://blog.csdn.net/coder_pig/article/details/39381479#L52" rel="#L52" style="color: rgb(102, 102, 102); text-decoration: none;">  52</a>
<a target=_blank id="L53" href="http://blog.csdn.net/coder_pig/article/details/39381479#L53" rel="#L53" style="color: rgb(102, 102, 102); text-decoration: none;">  53</a>
<a target=_blank id="L54" href="http://blog.csdn.net/coder_pig/article/details/39381479#L54" rel="#L54" style="color: rgb(102, 102, 102); text-decoration: none;">  54</a>
<a target=_blank id="L55" href="http://blog.csdn.net/coder_pig/article/details/39381479#L55" rel="#L55" style="color: rgb(102, 102, 102); text-decoration: none;">  55</a>
<a target=_blank id="L56" href="http://blog.csdn.net/coder_pig/article/details/39381479#L56" rel="#L56" style="color: rgb(102, 102, 102); text-decoration: none;">  56</a>
<a target=_blank id="L57" href="http://blog.csdn.net/coder_pig/article/details/39381479#L57" rel="#L57" style="color: rgb(102, 102, 102); text-decoration: none;">  57</a>
<a target=_blank id="L58" href="http://blog.csdn.net/coder_pig/article/details/39381479#L58" rel="#L58" style="color: rgb(102, 102, 102); text-decoration: none;">  58</a>
<a target=_blank id="L59" href="http://blog.csdn.net/coder_pig/article/details/39381479#L59" rel="#L59" style="color: rgb(102, 102, 102); text-decoration: none;">  59</a>
<a target=_blank id="L60" href="http://blog.csdn.net/coder_pig/article/details/39381479#L60" rel="#L60" style="color: rgb(102, 102, 102); text-decoration: none;">  60</a>
<a target=_blank id="L61" href="http://blog.csdn.net/coder_pig/article/details/39381479#L61" rel="#L61" style="color: rgb(102, 102, 102); text-decoration: none;">  61</a>
<a target=_blank id="L62" href="http://blog.csdn.net/coder_pig/article/details/39381479#L62" rel="#L62" style="color: rgb(102, 102, 102); text-decoration: none;">  62</a>
<a target=_blank id="L63" href="http://blog.csdn.net/coder_pig/article/details/39381479#L63" rel="#L63" style="color: rgb(102, 102, 102); text-decoration: none;">  63</a>
<a target=_blank id="L64" href="http://blog.csdn.net/coder_pig/article/details/39381479#L64" rel="#L64" style="color: rgb(102, 102, 102); text-decoration: none;">  64</a>
<a target=_blank id="L65" href="http://blog.csdn.net/coder_pig/article/details/39381479#L65" rel="#L65" style="color: rgb(102, 102, 102); text-decoration: none;">  65</a>
<a target=_blank id="L66" href="http://blog.csdn.net/coder_pig/article/details/39381479#L66" rel="#L66" style="color: rgb(102, 102, 102); text-decoration: none;">  66</a>
<a target=_blank id="L67" href="http://blog.csdn.net/coder_pig/article/details/39381479#L67" rel="#L67" style="color: rgb(102, 102, 102); text-decoration: none;">  67</a>
<a target=_blank id="L68" href="http://blog.csdn.net/coder_pig/article/details/39381479#L68" rel="#L68" style="color: rgb(102, 102, 102); text-decoration: none;">  68</a>
<a target=_blank id="L69" href="http://blog.csdn.net/coder_pig/article/details/39381479#L69" rel="#L69" style="color: rgb(102, 102, 102); text-decoration: none;">  69</a>
<a target=_blank id="L70" href="http://blog.csdn.net/coder_pig/article/details/39381479#L70" rel="#L70" style="color: rgb(102, 102, 102); text-decoration: none;">  70</a>
<a target=_blank id="L71" href="http://blog.csdn.net/coder_pig/article/details/39381479#L71" rel="#L71" style="color: rgb(102, 102, 102); text-decoration: none;">  71</a>
<a target=_blank id="L72" href="http://blog.csdn.net/coder_pig/article/details/39381479#L72" rel="#L72" style="color: rgb(102, 102, 102); text-decoration: none;">  72</a>
<a target=_blank id="L73" href="http://blog.csdn.net/coder_pig/article/details/39381479#L73" rel="#L73" style="color: rgb(102, 102, 102); text-decoration: none;">  73</a>
<a target=_blank id="L74" href="http://blog.csdn.net/coder_pig/article/details/39381479#L74" rel="#L74" style="color: rgb(102, 102, 102); text-decoration: none;">  74</a>
<a target=_blank id="L75" href="http://blog.csdn.net/coder_pig/article/details/39381479#L75" rel="#L75" style="color: rgb(102, 102, 102); text-decoration: none;">  75</a>
<a target=_blank id="L76" href="http://blog.csdn.net/coder_pig/article/details/39381479#L76" rel="#L76" style="color: rgb(102, 102, 102); text-decoration: none;">  76</a>
<a target=_blank id="L77" href="http://blog.csdn.net/coder_pig/article/details/39381479#L77" rel="#L77" style="color: rgb(102, 102, 102); text-decoration: none;">  77</a>
<a target=_blank id="L78" href="http://blog.csdn.net/coder_pig/article/details/39381479#L78" rel="#L78" style="color: rgb(102, 102, 102); text-decoration: none;">  78</a>
<a target=_blank id="L79" href="http://blog.csdn.net/coder_pig/article/details/39381479#L79" rel="#L79" style="color: rgb(102, 102, 102); text-decoration: none;">  79</a>
<a target=_blank id="L80" href="http://blog.csdn.net/coder_pig/article/details/39381479#L80" rel="#L80" style="color: rgb(102, 102, 102); text-decoration: none;">  80</a>
<a target=_blank id="L81" href="http://blog.csdn.net/coder_pig/article/details/39381479#L81" rel="#L81" style="color: rgb(102, 102, 102); text-decoration: none;">  81</a>
<a target=_blank id="L82" href="http://blog.csdn.net/coder_pig/article/details/39381479#L82" rel="#L82" style="color: rgb(102, 102, 102); text-decoration: none;">  82</a>
<a target=_blank id="L83" href="http://blog.csdn.net/coder_pig/article/details/39381479#L83" rel="#L83" style="color: rgb(102, 102, 102); text-decoration: none;">  83</a>
<a target=_blank id="L84" href="http://blog.csdn.net/coder_pig/article/details/39381479#L84" rel="#L84" style="color: rgb(102, 102, 102); text-decoration: none;">  84</a>
<a target=_blank id="L85" href="http://blog.csdn.net/coder_pig/article/details/39381479#L85" rel="#L85" style="color: rgb(102, 102, 102); text-decoration: none;">  85</a>
<a target=_blank id="L86" href="http://blog.csdn.net/coder_pig/article/details/39381479#L86" rel="#L86" style="color: rgb(102, 102, 102); text-decoration: none;">  86</a>
<a target=_blank id="L87" href="http://blog.csdn.net/coder_pig/article/details/39381479#L87" rel="#L87" style="color: rgb(102, 102, 102); text-decoration: none;">  87</a>
<a target=_blank id="L88" href="http://blog.csdn.net/coder_pig/article/details/39381479#L88" rel="#L88" style="color: rgb(102, 102, 102); text-decoration: none;">  88</a>
<a target=_blank id="L89" href="http://blog.csdn.net/coder_pig/article/details/39381479#L89" rel="#L89" style="color: rgb(102, 102, 102); text-decoration: none;">  89</a>
<a target=_blank id="L90" href="http://blog.csdn.net/coder_pig/article/details/39381479#L90" rel="#L90" style="color: rgb(102, 102, 102); text-decoration: none;">  90</a>
<a target=_blank id="L91" href="http://blog.csdn.net/coder_pig/article/details/39381479#L91" rel="#L91" style="color: rgb(102, 102, 102); text-decoration: none;">  91</a>
<a target=_blank id="L92" href="http://blog.csdn.net/coder_pig/article/details/39381479#L92" rel="#L92" style="color: rgb(102, 102, 102); text-decoration: none;">  92</a>
<a target=_blank id="L93" href="http://blog.csdn.net/coder_pig/article/details/39381479#L93" rel="#L93" style="color: rgb(102, 102, 102); text-decoration: none;">  93</a>
<a target=_blank id="L94" href="http://blog.csdn.net/coder_pig/article/details/39381479#L94" rel="#L94" style="color: rgb(102, 102, 102); text-decoration: none;">  94</a>
<a target=_blank id="L95" href="http://blog.csdn.net/coder_pig/article/details/39381479#L95" rel="#L95" style="color: rgb(102, 102, 102); text-decoration: none;">  95</a>
<a target=_blank id="L96" href="http://blog.csdn.net/coder_pig/article/details/39381479#L96" rel="#L96" style="color: rgb(102, 102, 102); text-decoration: none;">  96</a>
<a target=_blank id="L97" href="http://blog.csdn.net/coder_pig/article/details/39381479#L97" rel="#L97" style="color: rgb(102, 102, 102); text-decoration: none;">  97</a>
<a target=_blank id="L98" href="http://blog.csdn.net/coder_pig/article/details/39381479#L98" rel="#L98" style="color: rgb(102, 102, 102); text-decoration: none;">  98</a>
<a target=_blank id="L99" href="http://blog.csdn.net/coder_pig/article/details/39381479#L99" rel="#L99" style="color: rgb(102, 102, 102); text-decoration: none;">  99</a>
<a target=_blank id="L100" href="http://blog.csdn.net/coder_pig/article/details/39381479#L100" rel="#L100" style="color: rgb(102, 102, 102); text-decoration: none;"> 100</a>
<a target=_blank id="L101" href="http://blog.csdn.net/coder_pig/article/details/39381479#L101" rel="#L101" style="color: rgb(102, 102, 102); text-decoration: none;"> 101</a>
<a target=_blank id="L102" href="http://blog.csdn.net/coder_pig/article/details/39381479#L102" rel="#L102" style="color: rgb(102, 102, 102); text-decoration: none;"> 102</a>
<a target=_blank id="L103" href="http://blog.csdn.net/coder_pig/article/details/39381479#L103" rel="#L103" style="color: rgb(102, 102, 102); text-decoration: none;"> 103</a>
<a target=_blank id="L104" href="http://blog.csdn.net/coder_pig/article/details/39381479#L104" rel="#L104" style="color: rgb(102, 102, 102); text-decoration: none;"> 104</a>
<a target=_blank id="L105" href="http://blog.csdn.net/coder_pig/article/details/39381479#L105" rel="#L105" style="color: rgb(102, 102, 102); text-decoration: none;"> 105</a>
<a target=_blank id="L106" href="http://blog.csdn.net/coder_pig/article/details/39381479#L106" rel="#L106" style="color: rgb(102, 102, 102); text-decoration: none;"> 106</a>
<a target=_blank id="L107" href="http://blog.csdn.net/coder_pig/article/details/39381479#L107" rel="#L107" style="color: rgb(102, 102, 102); text-decoration: none;"> 107</a>
<a target=_blank id="L108" href="http://blog.csdn.net/coder_pig/article/details/39381479#L108" rel="#L108" style="color: rgb(102, 102, 102); text-decoration: none;"> 108</a>
<a target=_blank id="L109" href="http://blog.csdn.net/coder_pig/article/details/39381479#L109" rel="#L109" style="color: rgb(102, 102, 102); text-decoration: none;"> 109</a>
<a target=_blank id="L110" href="http://blog.csdn.net/coder_pig/article/details/39381479#L110" rel="#L110" style="color: rgb(102, 102, 102); text-decoration: none;"> 110</a>
<a target=_blank id="L111" href="http://blog.csdn.net/coder_pig/article/details/39381479#L111" rel="#L111" style="color: rgb(102, 102, 102); text-decoration: none;"> 111</a>
<a target=_blank id="L112" href="http://blog.csdn.net/coder_pig/article/details/39381479#L112" rel="#L112" style="color: rgb(102, 102, 102); text-decoration: none;"> 112</a>
<a target=_blank id="L113" href="http://blog.csdn.net/coder_pig/article/details/39381479#L113" rel="#L113" style="color: rgb(102, 102, 102); text-decoration: none;"> 113</a>
<a target=_blank id="L114" href="http://blog.csdn.net/coder_pig/article/details/39381479#L114" rel="#L114" style="color: rgb(102, 102, 102); text-decoration: none;"> 114</a>
<a target=_blank id="L115" href="http://blog.csdn.net/coder_pig/article/details/39381479#L115" rel="#L115" style="color: rgb(102, 102, 102); text-decoration: none;"> 115</a>
<a target=_blank id="L116" href="http://blog.csdn.net/coder_pig/article/details/39381479#L116" rel="#L116" style="color: rgb(102, 102, 102); text-decoration: none;"> 116</a>
<a target=_blank id="L117" href="http://blog.csdn.net/coder_pig/article/details/39381479#L117" rel="#L117" style="color: rgb(102, 102, 102); text-decoration: none;"> 117</a>
<a target=_blank id="L118" href="http://blog.csdn.net/coder_pig/article/details/39381479#L118" rel="#L118" style="color: rgb(102, 102, 102); text-decoration: none;"> 118</a>
<a target=_blank id="L119" href="http://blog.csdn.net/coder_pig/article/details/39381479#L119" rel="#L119" style="color: rgb(102, 102, 102); text-decoration: none;"> 119</a>
<a target=_blank id="L120" href="http://blog.csdn.net/coder_pig/article/details/39381479#L120" rel="#L120" style="color: rgb(102, 102, 102); text-decoration: none;"> 120</a>
<a target=_blank id="L121" href="http://blog.csdn.net/coder_pig/article/details/39381479#L121" rel="#L121" style="color: rgb(102, 102, 102); text-decoration: none;"> 121</a>
<a target=_blank id="L122" href="http://blog.csdn.net/coder_pig/article/details/39381479#L122" rel="#L122" style="color: rgb(102, 102, 102); text-decoration: none;"> 122</a>
<a target=_blank id="L123" href="http://blog.csdn.net/coder_pig/article/details/39381479#L123" rel="#L123" style="color: rgb(102, 102, 102); text-decoration: none;"> 123</a>
<a target=_blank id="L124" href="http://blog.csdn.net/coder_pig/article/details/39381479#L124" rel="#L124" style="color: rgb(102, 102, 102); text-decoration: none;"> 124</a>
<a target=_blank id="L125" href="http://blog.csdn.net/coder_pig/article/details/39381479#L125" rel="#L125" style="color: rgb(102, 102, 102); text-decoration: none;"> 125</a>
<a target=_blank id="L126" href="http://blog.csdn.net/coder_pig/article/details/39381479#L126" rel="#L126" style="color: rgb(102, 102, 102); text-decoration: none;"> 126</a>
<a target=_blank id="L127" href="http://blog.csdn.net/coder_pig/article/details/39381479#L127" rel="#L127" style="color: rgb(102, 102, 102); text-decoration: none;"> 127</a>
<a target=_blank id="L128" href="http://blog.csdn.net/coder_pig/article/details/39381479#L128" rel="#L128" style="color: rgb(102, 102, 102); text-decoration: none;"> 128</a>
<a target=_blank id="L129" href="http://blog.csdn.net/coder_pig/article/details/39381479#L129" rel="#L129" style="color: rgb(102, 102, 102); text-decoration: none;"> 129</a>
<a target=_blank id="L130" href="http://blog.csdn.net/coder_pig/article/details/39381479#L130" rel="#L130" style="color: rgb(102, 102, 102); text-decoration: none;"> 130</a>
<a target=_blank id="L131" href="http://blog.csdn.net/coder_pig/article/details/39381479#L131" rel="#L131" style="color: rgb(102, 102, 102); text-decoration: none;"> 131</a>
<a target=_blank id="L132" href="http://blog.csdn.net/coder_pig/article/details/39381479#L132" rel="#L132" style="color: rgb(102, 102, 102); text-decoration: none;"> 132</a>
<a target=_blank id="L133" href="http://blog.csdn.net/coder_pig/article/details/39381479#L133" rel="#L133" style="color: rgb(102, 102, 102); text-decoration: none;"> 133</a>
<a target=_blank id="L134" href="http://blog.csdn.net/coder_pig/article/details/39381479#L134" rel="#L134" style="color: rgb(102, 102, 102); text-decoration: none;"> 134</a>
<a target=_blank id="L135" href="http://blog.csdn.net/coder_pig/article/details/39381479#L135" rel="#L135" style="color: rgb(102, 102, 102); text-decoration: none;"> 135</a>
<a target=_blank id="L136" href="http://blog.csdn.net/coder_pig/article/details/39381479#L136" rel="#L136" style="color: rgb(102, 102, 102); text-decoration: none;"> 136</a>
<a target=_blank id="L137" href="http://blog.csdn.net/coder_pig/article/details/39381479#L137" rel="#L137" style="color: rgb(102, 102, 102); text-decoration: none;"> 137</a>
<a target=_blank id="L138" href="http://blog.csdn.net/coder_pig/article/details/39381479#L138" rel="#L138" style="color: rgb(102, 102, 102); text-decoration: none;"> 138</a>
<a target=_blank id="L139" href="http://blog.csdn.net/coder_pig/article/details/39381479#L139" rel="#L139" style="color: rgb(102, 102, 102); text-decoration: none;"> 139</a>
<a target=_blank id="L140" href="http://blog.csdn.net/coder_pig/article/details/39381479#L140" rel="#L140" style="color: rgb(102, 102, 102); text-decoration: none;"> 140</a>
<a target=_blank id="L141" href="http://blog.csdn.net/coder_pig/article/details/39381479#L141" rel="#L141" style="color: rgb(102, 102, 102); text-decoration: none;"> 141</a>
<a target=_blank id="L142" href="http://blog.csdn.net/coder_pig/article/details/39381479#L142" rel="#L142" style="color: rgb(102, 102, 102); text-decoration: none;"> 142</a>
<a target=_blank id="L143" href="http://blog.csdn.net/coder_pig/article/details/39381479#L143" rel="#L143" style="color: rgb(102, 102, 102); text-decoration: none;"> 143</a>
<a target=_blank id="L144" href="http://blog.csdn.net/coder_pig/article/details/39381479#L144" rel="#L144" style="color: rgb(102, 102, 102); text-decoration: none;"> 144</a>
<a target=_blank id="L145" href="http://blog.csdn.net/coder_pig/article/details/39381479#L145" rel="#L145" style="color: rgb(102, 102, 102); text-decoration: none;"> 145</a>
<a target=_blank id="L146" href="http://blog.csdn.net/coder_pig/article/details/39381479#L146" rel="#L146" style="color: rgb(102, 102, 102); text-decoration: none;"> 146</a>
<a target=_blank id="L147" href="http://blog.csdn.net/coder_pig/article/details/39381479#L147" rel="#L147" style="color: rgb(102, 102, 102); text-decoration: none;"> 147</a>
<a target=_blank id="L148" href="http://blog.csdn.net/coder_pig/article/details/39381479#L148" rel="#L148" style="color: rgb(102, 102, 102); text-decoration: none;"> 148</a>
<a target=_blank id="L149" href="http://blog.csdn.net/coder_pig/article/details/39381479#L149" rel="#L149" style="color: rgb(102, 102, 102); text-decoration: none;"> 149</a>
<a target=_blank id="L150" href="http://blog.csdn.net/coder_pig/article/details/39381479#L150" rel="#L150" style="color: rgb(102, 102, 102); text-decoration: none;"> 150</a>
<a target=_blank id="L151" href="http://blog.csdn.net/coder_pig/article/details/39381479#L151" rel="#L151" style="color: rgb(102, 102, 102); text-decoration: none;"> 151</a>
<a target=_blank id="L152" href="http://blog.csdn.net/coder_pig/article/details/39381479#L152" rel="#L152" style="color: rgb(102, 102, 102); text-decoration: none;"> 152</a>
<a target=_blank id="L153" href="http://blog.csdn.net/coder_pig/article/details/39381479#L153" rel="#L153" style="color: rgb(102, 102, 102); text-decoration: none;"> 153</a>
<a target=_blank id="L154" href="http://blog.csdn.net/coder_pig/article/details/39381479#L154" rel="#L154" style="color: rgb(102, 102, 102); text-decoration: none;"> 154</a>
<a target=_blank id="L155" href="http://blog.csdn.net/coder_pig/article/details/39381479#L155" rel="#L155" style="color: rgb(102, 102, 102); text-decoration: none;"> 155</a>
<a target=_blank id="L156" href="http://blog.csdn.net/coder_pig/article/details/39381479#L156" rel="#L156" style="color: rgb(102, 102, 102); text-decoration: none;"> 156</a>
<a target=_blank id="L157" href="http://blog.csdn.net/coder_pig/article/details/39381479#L157" rel="#L157" style="color: rgb(102, 102, 102); text-decoration: none;"> 157</a>
<a target=_blank id="L158" href="http://blog.csdn.net/coder_pig/article/details/39381479#L158" rel="#L158" style="color: rgb(102, 102, 102); text-decoration: none;"> 158</a>
<a target=_blank id="L159" href="http://blog.csdn.net/coder_pig/article/details/39381479#L159" rel="#L159" style="color: rgb(102, 102, 102); text-decoration: none;"> 159</a>
<a target=_blank id="L160" href="http://blog.csdn.net/coder_pig/article/details/39381479#L160" rel="#L160" style="color: rgb(102, 102, 102); text-decoration: none;"> 160</a>
<a target=_blank id="L161" href="http://blog.csdn.net/coder_pig/article/details/39381479#L161" rel="#L161" style="color: rgb(102, 102, 102); text-decoration: none;"> 161</a>
<a target=_blank id="L162" href="http://blog.csdn.net/coder_pig/article/details/39381479#L162" rel="#L162" style="color: rgb(102, 102, 102); text-decoration: none;"> 162</a>
<a target=_blank id="L163" href="http://blog.csdn.net/coder_pig/article/details/39381479#L163" rel="#L163" style="color: rgb(102, 102, 102); text-decoration: none;"> 163</a>
<a target=_blank id="L164" href="http://blog.csdn.net/coder_pig/article/details/39381479#L164" rel="#L164" style="color: rgb(102, 102, 102); text-decoration: none;"> 164</a>
<a target=_blank id="L165" href="http://blog.csdn.net/coder_pig/article/details/39381479#L165" rel="#L165" style="color: rgb(102, 102, 102); text-decoration: none;"> 165</a>
<a target=_blank id="L166" href="http://blog.csdn.net/coder_pig/article/details/39381479#L166" rel="#L166" style="color: rgb(102, 102, 102); text-decoration: none;"> 166</a>
<a target=_blank id="L167" href="http://blog.csdn.net/coder_pig/article/details/39381479#L167" rel="#L167" style="color: rgb(102, 102, 102); text-decoration: none;"> 167</a>
<a target=_blank id="L168" href="http://blog.csdn.net/coder_pig/article/details/39381479#L168" rel="#L168" style="color: rgb(102, 102, 102); text-decoration: none;"> 168</a>
<a target=_blank id="L169" href="http://blog.csdn.net/coder_pig/article/details/39381479#L169" rel="#L169" style="color: rgb(102, 102, 102); text-decoration: none;"> 169</a>
<a target=_blank id="L170" href="http://blog.csdn.net/coder_pig/article/details/39381479#L170" rel="#L170" style="color: rgb(102, 102, 102); text-decoration: none;"> 170</a>
<a target=_blank id="L171" href="http://blog.csdn.net/coder_pig/article/details/39381479#L171" rel="#L171" style="color: rgb(102, 102, 102); text-decoration: none;"> 171</a>
<a target=_blank id="L172" href="http://blog.csdn.net/coder_pig/article/details/39381479#L172" rel="#L172" style="color: rgb(102, 102, 102); text-decoration: none;"> 172</a>
<a target=_blank id="L173" href="http://blog.csdn.net/coder_pig/article/details/39381479#L173" rel="#L173" style="color: rgb(102, 102, 102); text-decoration: none;"> 173</a>
<a target=_blank id="L174" href="http://blog.csdn.net/coder_pig/article/details/39381479#L174" rel="#L174" style="color: rgb(102, 102, 102); text-decoration: none;"> 174</a>
<a target=_blank id="L175" href="http://blog.csdn.net/coder_pig/article/details/39381479#L175" rel="#L175" style="color: rgb(102, 102, 102); text-decoration: none;"> 175</a>
<a target=_blank id="L176" href="http://blog.csdn.net/coder_pig/article/details/39381479#L176" rel="#L176" style="color: rgb(102, 102, 102); text-decoration: none;"> 176</a>
<a target=_blank id="L177" href="http://blog.csdn.net/coder_pig/article/details/39381479#L177" rel="#L177" style="color: rgb(102, 102, 102); text-decoration: none;"> 177</a>
<a target=_blank id="L178" href="http://blog.csdn.net/coder_pig/article/details/39381479#L178" rel="#L178" style="color: rgb(102, 102, 102); text-decoration: none;"> 178</a>
<a target=_blank id="L179" href="http://blog.csdn.net/coder_pig/article/details/39381479#L179" rel="#L179" style="color: rgb(102, 102, 102); text-decoration: none;"> 179</a>
<a target=_blank id="L180" href="http://blog.csdn.net/coder_pig/article/details/39381479#L180" rel="#L180" style="color: rgb(102, 102, 102); text-decoration: none;"> 180</a>
<a target=_blank id="L181" href="http://blog.csdn.net/coder_pig/article/details/39381479#L181" rel="#L181" style="color: rgb(102, 102, 102); text-decoration: none;"> 181</a>
<a target=_blank id="L182" href="http://blog.csdn.net/coder_pig/article/details/39381479#L182" rel="#L182" style="color: rgb(102, 102, 102); text-decoration: none;"> 182</a>
<a target=_blank id="L183" href="http://blog.csdn.net/coder_pig/article/details/39381479#L183" rel="#L183" style="color: rgb(102, 102, 102); text-decoration: none;"> 183</a>
<a target=_blank id="L184" href="http://blog.csdn.net/coder_pig/article/details/39381479#L184" rel="#L184" style="color: rgb(102, 102, 102); text-decoration: none;"> 184</a>
<a target=_blank id="L185" href="http://blog.csdn.net/coder_pig/article/details/39381479#L185" rel="#L185" style="color: rgb(102, 102, 102); text-decoration: none;"> 185</a>
<a target=_blank id="L186" href="http://blog.csdn.net/coder_pig/article/details/39381479#L186" rel="#L186" style="color: rgb(102, 102, 102); text-decoration: none;"> 186</a>
<a target=_blank id="L187" href="http://blog.csdn.net/coder_pig/article/details/39381479#L187" rel="#L187" style="color: rgb(102, 102, 102); text-decoration: none;"> 187</a>
<a target=_blank id="L188" href="http://blog.csdn.net/coder_pig/article/details/39381479#L188" rel="#L188" style="color: rgb(102, 102, 102); text-decoration: none;"> 188</a>
<a target=_blank id="L189" href="http://blog.csdn.net/coder_pig/article/details/39381479#L189" rel="#L189" style="color: rgb(102, 102, 102); text-decoration: none;"> 189</a>
<a target=_blank id="L190" href="http://blog.csdn.net/coder_pig/article/details/39381479#L190" rel="#L190" style="color: rgb(102, 102, 102); text-decoration: none;"> 190</a>
<a target=_blank id="L191" href="http://blog.csdn.net/coder_pig/article/details/39381479#L191" rel="#L191" style="color: rgb(102, 102, 102); text-decoration: none;"> 191</a>
<a target=_blank id="L192" href="http://blog.csdn.net/coder_pig/article/details/39381479#L192" rel="#L192" style="color: rgb(102, 102, 102); text-decoration: none;"> 192</a>
<a target=_blank id="L193" href="http://blog.csdn.net/coder_pig/article/details/39381479#L193" rel="#L193" style="color: rgb(102, 102, 102); text-decoration: none;"> 193</a>
<a target=_blank id="L194" href="http://blog.csdn.net/coder_pig/article/details/39381479#L194" rel="#L194" style="color: rgb(102, 102, 102); text-decoration: none;"> 194</a>
<a target=_blank id="L195" href="http://blog.csdn.net/coder_pig/article/details/39381479#L195" rel="#L195" style="color: rgb(102, 102, 102); text-decoration: none;"> 195</a>
<a target=_blank id="L196" href="http://blog.csdn.net/coder_pig/article/details/39381479#L196" rel="#L196" style="color: rgb(102, 102, 102); text-decoration: none;"> 196</a>
<a target=_blank id="L197" href="http://blog.csdn.net/coder_pig/article/details/39381479#L197" rel="#L197" style="color: rgb(102, 102, 102); text-decoration: none;"> 197</a>
<a target=_blank id="L198" href="http://blog.csdn.net/coder_pig/article/details/39381479#L198" rel="#L198" style="color: rgb(102, 102, 102); text-decoration: none;"> 198</a>
<a target=_blank id="L199" href="http://blog.csdn.net/coder_pig/article/details/39381479#L199" rel="#L199" style="color: rgb(102, 102, 102); text-decoration: none;"> 199</a>
<a target=_blank id="L200" href="http://blog.csdn.net/coder_pig/article/details/39381479#L200" rel="#L200" style="color: rgb(102, 102, 102); text-decoration: none;"> 200</a>
<a target=_blank id="L201" href="http://blog.csdn.net/coder_pig/article/details/39381479#L201" rel="#L201" style="color: rgb(102, 102, 102); text-decoration: none;"> 201</a>
<a target=_blank id="L202" href="http://blog.csdn.net/coder_pig/article/details/39381479#L202" rel="#L202" style="color: rgb(102, 102, 102); text-decoration: none;"> 202</a>
<a target=_blank id="L203" href="http://blog.csdn.net/coder_pig/article/details/39381479#L203" rel="#L203" style="color: rgb(102, 102, 102); text-decoration: none;"> 203</a>
<a target=_blank id="L204" href="http://blog.csdn.net/coder_pig/article/details/39381479#L204" rel="#L204" style="color: rgb(102, 102, 102); text-decoration: none;"> 204</a>
<a target=_blank id="L205" href="http://blog.csdn.net/coder_pig/article/details/39381479#L205" rel="#L205" style="color: rgb(102, 102, 102); text-decoration: none;"> 205</a>
<a target=_blank id="L206" href="http://blog.csdn.net/coder_pig/article/details/39381479#L206" rel="#L206" style="color: rgb(102, 102, 102); text-decoration: none;"> 206</a>
<a target=_blank id="L207" href="http://blog.csdn.net/coder_pig/article/details/39381479#L207" rel="#L207" style="color: rgb(102, 102, 102); text-decoration: none;"> 207</a>
<a target=_blank id="L208" href="http://blog.csdn.net/coder_pig/article/details/39381479#L208" rel="#L208" style="color: rgb(102, 102, 102); text-decoration: none;"> 208</a>
<a target=_blank id="L209" href="http://blog.csdn.net/coder_pig/article/details/39381479#L209" rel="#L209" style="color: rgb(102, 102, 102); text-decoration: none;"> 209</a>
<a target=_blank id="L210" href="http://blog.csdn.net/coder_pig/article/details/39381479#L210" rel="#L210" style="color: rgb(102, 102, 102); text-decoration: none;"> 210</a>
<a target=_blank id="L211" href="http://blog.csdn.net/coder_pig/article/details/39381479#L211" rel="#L211" style="color: rgb(102, 102, 102); text-decoration: none;"> 211</a>
<a target=_blank id="L212" href="http://blog.csdn.net/coder_pig/article/details/39381479#L212" rel="#L212" style="color: rgb(102, 102, 102); text-decoration: none;"> 212</a>
<a target=_blank id="L213" href="http://blog.csdn.net/coder_pig/article/details/39381479#L213" rel="#L213" style="color: rgb(102, 102, 102); text-decoration: none;"> 213</a>
<a target=_blank id="L214" href="http://blog.csdn.net/coder_pig/article/details/39381479#L214" rel="#L214" style="color: rgb(102, 102, 102); text-decoration: none;"> 214</a>
<a target=_blank id="L215" href="http://blog.csdn.net/coder_pig/article/details/39381479#L215" rel="#L215" style="color: rgb(102, 102, 102); text-decoration: none;"> 215</a>
<a target=_blank id="L216" href="http://blog.csdn.net/coder_pig/article/details/39381479#L216" rel="#L216" style="color: rgb(102, 102, 102); text-decoration: none;"> 216</a>
<a target=_blank id="L217" href="http://blog.csdn.net/coder_pig/article/details/39381479#L217" rel="#L217" style="color: rgb(102, 102, 102); text-decoration: none;"> 217</a>
<a target=_blank id="L218" href="http://blog.csdn.net/coder_pig/article/details/39381479#L218" rel="#L218" style="color: rgb(102, 102, 102); text-decoration: none;"> 218</a>
<a target=_blank id="L219" href="http://blog.csdn.net/coder_pig/article/details/39381479#L219" rel="#L219" style="color: rgb(102, 102, 102); text-decoration: none;"> 219</a>
<a target=_blank id="L220" href="http://blog.csdn.net/coder_pig/article/details/39381479#L220" rel="#L220" style="color: rgb(102, 102, 102); text-decoration: none;"> 220</a>
<a target=_blank id="L221" href="http://blog.csdn.net/coder_pig/article/details/39381479#L221" rel="#L221" style="color: rgb(102, 102, 102); text-decoration: none;"> 221</a>
<a target=_blank id="L222" href="http://blog.csdn.net/coder_pig/article/details/39381479#L222" rel="#L222" style="color: rgb(102, 102, 102); text-decoration: none;"> 222</a>
<a target=_blank id="L223" href="http://blog.csdn.net/coder_pig/article/details/39381479#L223" rel="#L223" style="color: rgb(102, 102, 102); text-decoration: none;"> 223</a>
<a target=_blank id="L224" href="http://blog.csdn.net/coder_pig/article/details/39381479#L224" rel="#L224" style="color: rgb(102, 102, 102); text-decoration: none;"> 224</a>
<a target=_blank id="L225" href="http://blog.csdn.net/coder_pig/article/details/39381479#L225" rel="#L225" style="color: rgb(102, 102, 102); text-decoration: none;"> 225</a>
<a target=_blank id="L226" href="http://blog.csdn.net/coder_pig/article/details/39381479#L226" rel="#L226" style="color: rgb(102, 102, 102); text-decoration: none;"> 226</a>
<a target=_blank id="L227" href="http://blog.csdn.net/coder_pig/article/details/39381479#L227" rel="#L227" style="color: rgb(102, 102, 102); text-decoration: none;"> 227</a>
<a target=_blank id="L228" href="http://blog.csdn.net/coder_pig/article/details/39381479#L228" rel="#L228" style="color: rgb(102, 102, 102); text-decoration: none;"> 228</a>
<a target=_blank id="L229" href="http://blog.csdn.net/coder_pig/article/details/39381479#L229" rel="#L229" style="color: rgb(102, 102, 102); text-decoration: none;"> 229</a>
<a target=_blank id="L230" href="http://blog.csdn.net/coder_pig/article/details/39381479#L230" rel="#L230" style="color: rgb(102, 102, 102); text-decoration: none;"> 230</a>
<a target=_blank id="L231" href="http://blog.csdn.net/coder_pig/article/details/39381479#L231" rel="#L231" style="color: rgb(102, 102, 102); text-decoration: none;"> 231</a>
<a target=_blank id="L232" href="http://blog.csdn.net/coder_pig/article/details/39381479#L232" rel="#L232" style="color: rgb(102, 102, 102); text-decoration: none;"> 232</a>
<a target=_blank id="L233" href="http://blog.csdn.net/coder_pig/article/details/39381479#L233" rel="#L233" style="color: rgb(102, 102, 102); text-decoration: none;"> 233</a>
<a target=_blank id="L234" href="http://blog.csdn.net/coder_pig/article/details/39381479#L234" rel="#L234" style="color: rgb(102, 102, 102); text-decoration: none;"> 234</a>
<a target=_blank id="L235" href="http://blog.csdn.net/coder_pig/article/details/39381479#L235" rel="#L235" style="color: rgb(102, 102, 102); text-decoration: none;"> 235</a>
<a target=_blank id="L236" href="http://blog.csdn.net/coder_pig/article/details/39381479#L236" rel="#L236" style="color: rgb(102, 102, 102); text-decoration: none;"> 236</a>
<a target=_blank id="L237" href="http://blog.csdn.net/coder_pig/article/details/39381479#L237" rel="#L237" style="color: rgb(102, 102, 102); text-decoration: none;"> 237</a>
<a target=_blank id="L238" href="http://blog.csdn.net/coder_pig/article/details/39381479#L238" rel="#L238" style="color: rgb(102, 102, 102); text-decoration: none;"> 238</a>
<a target=_blank id="L239" href="http://blog.csdn.net/coder_pig/article/details/39381479#L239" rel="#L239" style="color: rgb(102, 102, 102); text-decoration: none;"> 239</a>
<a target=_blank id="L240" href="http://blog.csdn.net/coder_pig/article/details/39381479#L240" rel="#L240" style="color: rgb(102, 102, 102); text-decoration: none;"> 240</a>
<a target=_blank id="L241" href="http://blog.csdn.net/coder_pig/article/details/39381479#L241" rel="#L241" style="color: rgb(102, 102, 102); text-decoration: none;"> 241</a>
<a target=_blank id="L242" href="http://blog.csdn.net/coder_pig/article/details/39381479#L242" rel="#L242" style="color: rgb(102, 102, 102); text-decoration: none;"> 242</a>
<a target=_blank id="L243" href="http://blog.csdn.net/coder_pig/article/details/39381479#L243" rel="#L243" style="color: rgb(102, 102, 102); text-decoration: none;"> 243</a>
<a target=_blank id="L244" href="http://blog.csdn.net/coder_pig/article/details/39381479#L244" rel="#L244" style="color: rgb(102, 102, 102); text-decoration: none;"> 244</a>
<a target=_blank id="L245" href="http://blog.csdn.net/coder_pig/article/details/39381479#L245" rel="#L245" style="color: rgb(102, 102, 102); text-decoration: none;"> 245</a>
<a target=_blank id="L246" href="http://blog.csdn.net/coder_pig/article/details/39381479#L246" rel="#L246" style="color: rgb(102, 102, 102); text-decoration: none;"> 246</a>
<a target=_blank id="L247" href="http://blog.csdn.net/coder_pig/article/details/39381479#L247" rel="#L247" style="color: rgb(102, 102, 102); text-decoration: none;"> 247</a>
<a target=_blank id="L248" href="http://blog.csdn.net/coder_pig/article/details/39381479#L248" rel="#L248" style="color: rgb(102, 102, 102); text-decoration: none;"> 248</a>
<a target=_blank id="L249" href="http://blog.csdn.net/coder_pig/article/details/39381479#L249" rel="#L249" style="color: rgb(102, 102, 102); text-decoration: none;"> 249</a>
<a target=_blank id="L250" href="http://blog.csdn.net/coder_pig/article/details/39381479#L250" rel="#L250" style="color: rgb(102, 102, 102); text-decoration: none;"> 250</a>
<a target=_blank id="L251" href="http://blog.csdn.net/coder_pig/article/details/39381479#L251" rel="#L251" style="color: rgb(102, 102, 102); text-decoration: none;"> 251</a>
<a target=_blank id="L252" href="http://blog.csdn.net/coder_pig/article/details/39381479#L252" rel="#L252" style="color: rgb(102, 102, 102); text-decoration: none;"> 252</a>
<a target=_blank id="L253" href="http://blog.csdn.net/coder_pig/article/details/39381479#L253" rel="#L253" style="color: rgb(102, 102, 102); text-decoration: none;"> 253</a>
<a target=_blank id="L254" href="http://blog.csdn.net/coder_pig/article/details/39381479#L254" rel="#L254" style="color: rgb(102, 102, 102); text-decoration: none;"> 254</a>
<a target=_blank id="L255" href="http://blog.csdn.net/coder_pig/article/details/39381479#L255" rel="#L255" style="color: rgb(102, 102, 102); text-decoration: none;"> 255</a>
<a target=_blank id="L256" href="http://blog.csdn.net/coder_pig/article/details/39381479#L256" rel="#L256" style="color: rgb(102, 102, 102); text-decoration: none;"> 256</a>
<a target=_blank id="L257" href="http://blog.csdn.net/coder_pig/article/details/39381479#L257" rel="#L257" style="color: rgb(102, 102, 102); text-decoration: none;"> 257</a>
<a target=_blank id="L258" href="http://blog.csdn.net/coder_pig/article/details/39381479#L258" rel="#L258" style="color: rgb(102, 102, 102); text-decoration: none;"> 258</a>
<a target=_blank id="L259" href="http://blog.csdn.net/coder_pig/article/details/39381479#L259" rel="#L259" style="color: rgb(102, 102, 102); text-decoration: none;"> 259</a>
           
           
public class SocketHttpRequester
{
/**
* 发送xml数据
* @param path 请求地址
* @param xml xml数据
* @param encoding 编码
* @return
* @throws Exception
*/
public static byte [] postXml ( String path , String xml , String encoding ) throws Exception {
byte [] data = xml . getBytes ( encoding );
URL url = new URL ( path );
HttpURLConnection conn = ( HttpURLConnection ) url . openConnection ();
conn . setRequestMethod ( "POST" );
conn . setDoOutput ( true );
conn . setRequestProperty ( "Content-Type" , "text/xml; charset=" + encoding );
conn . setRequestProperty ( "Content-Length" , String . valueOf ( data . length ));
conn . setConnectTimeout ( 5 * 1000 );
OutputStream outStream = conn . getOutputStream ();
outStream . write ( data );
outStream . flush ();
outStream . close ();
if ( conn . getResponseCode ()== 200 ){
return readStream ( conn . getInputStream ());
}
return null ;
}
/**
* 直接通过HTTP协议提交数据到服务器,实现如下面表单提交功能:
* <FORM METHOD=POST ACTION="http://192.168.0.200:8080/ssi/fileload/test.do" enctype="multipart/form-data">
<INPUT TYPE="text" NAME="name">
<INPUT TYPE="text" NAME="id">
<input type="file" name="imagefile"/>
<input type="file" name="zip"/>
</FORM>
* @param path 上传路径(注:避免使用localhost或127.0.0.1这样的路径测试,
* 因为它会指向手机模拟器,你可以使用http://www.baidu.com或http://192.168.1.10:8080这样的路径测试)
* @param params 请求参数 key为参数名,value为参数值
* @param file 上传文件
*/
public static boolean post ( String path , Map < String , String > params , FormFile [] files ) throws Exception
{
//数据分隔线
final String BOUNDARY = "---------------------------7da2137580612" ;
//数据结束标志"---------------------------7da2137580612--"
final String endline = "--" + BOUNDARY + "--/r/n" ;
//下面两个for循环都是为了得到数据长度参数,依据表单的类型而定
//首先得到文件类型数据的总长度(包括文件分割线)
int fileDataLength = 0 ;
for ( FormFile uploadFile : files )
{
StringBuilder fileExplain = new StringBuilder ();
fileExplain . append ( "--" );
fileExplain . append ( BOUNDARY );
fileExplain . append ( "/r/n" );
fileExplain . append ( "Content-Disposition: form-data;name=/""+ uploadFile.getParameterName()+" / ";filename=/""+ uploadFile.getFilname() + " / "/r/n" );
fileExplain . append ( "Content-Type: " + uploadFile . getContentType ()+ "/r/n/r/n" );
fileExplain . append ( "/r/n" );
fileDataLength += fileExplain . length ();
if ( uploadFile . getInStream ()!= null ){
fileDataLength += uploadFile . getFile (). length ();
} else {
fileDataLength += uploadFile . getData (). length ;
}
}
//再构造文本类型参数的实体数据
StringBuilder textEntity = new StringBuilder ();
for ( Map . Entry < String , String > entry : params . entrySet ())
{
textEntity . append ( "--" );
textEntity . append ( BOUNDARY );
textEntity . append ( "/r/n" );
textEntity . append ( "Content-Disposition: form-data; name=/""+ entry.getKey() + " / "/r/n/r/n" );
textEntity . append ( entry . getValue ());
textEntity . append ( "/r/n" );
}
//计算传输给服务器的实体数据总长度(文本总长度+数据总长度+分隔符)
int dataLength = textEntity . toString (). getBytes (). length + fileDataLength + endline . getBytes (). length ;
URL url = new URL ( path );
//默认端口号其实可以不写
int port = url . getPort ()==- 1 ? 80 : url . getPort ();
//建立一个Socket链接
Socket socket = new Socket ( InetAddress . getByName ( url . getHost ()), port );
//获得一个输出流(从Android流到web)
OutputStream outStream = socket . getOutputStream ();
//下面完成HTTP请求头的发送
String requestmethod = "POST " + url . getPath ()+ " HTTP/1.1/r/n" ;
outStream . write ( requestmethod . getBytes ());
//构建accept
String accept = "Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*/r/n" ;
outStream . write ( accept . getBytes ());
//构建language
String language = "Accept-Language: zh-CN/r/n" ;
outStream . write ( language . getBytes ());
//构建contenttype
String contenttype = "Content-Type: multipart/form-data; boundary=" + BOUNDARY + "/r/n" ;
outStream . write ( contenttype . getBytes ());
//构建contentlength
String contentlength = "Content-Length: " + dataLength + "/r/n" ;
outStream . write ( contentlength . getBytes ());
//构建alive
String alive = "Connection: Keep-Alive/r/n" ;
outStream . write ( alive . getBytes ());
//构建host
String host = "Host: " + url . getHost () + ":" + port + "/r/n" ;
outStream . write ( host . getBytes ());
//写完HTTP请求头后根据HTTP协议再写一个回车换行
outStream . write ( "/r/n" . getBytes ());
//把所有文本类型的实体数据发送出来
outStream . write ( textEntity . toString (). getBytes ());
//把所有文件类型的实体数据发送出来
for ( FormFile uploadFile : files )
{
StringBuilder fileEntity = new StringBuilder ();
fileEntity . append ( "--" );
fileEntity . append ( BOUNDARY );
fileEntity . append ( "/r/n" );
fileEntity . append ( "Content-Disposition: form-data;name=/""+ uploadFile.getParameterName()+" / ";filename=/""+ uploadFile.getFilname() + " / "/r/n" );
fileEntity . append ( "Content-Type: " + uploadFile . getContentType ()+ "/r/n/r/n" );
outStream . write ( fileEntity . toString (). getBytes ());
//边读边写
if ( uploadFile . getInStream ()!= null )
{
byte [] buffer = new byte [ 1024 ];
int len = 0 ;
while (( len = uploadFile . getInStream (). read ( buffer , 0 , 1024 ))!=- 1 )
{
outStream . write ( buffer , 0 , len );
}
uploadFile . getInStream (). close ();
}
else
{
outStream . write ( uploadFile . getData (), 0 , uploadFile . getData (). length );
}
outStream . write ( "/r/n" . getBytes ());
}
//下面发送数据结束标志,表示数据已经结束
outStream . write ( endline . getBytes ());
BufferedReader reader = new BufferedReader ( new InputStreamReader ( socket . getInputStream ()));
//读取web服务器返回的数据,判断请求码是否为200,如果不是200,代表请求失败
if ( reader . readLine (). indexOf ( "200" )==- 1 )
{
return false ;
}
outStream . flush ();
outStream . close ();
reader . close ();
socket . close ();
return true ;
}
/**
* 提交数据到服务器
* @param path 上传路径(注:避免使用localhost或127.0.0.1这样的路径测试,因为它会指向手机模拟器,你可以使用http://www.baidu.com或http://192.168.1.10:8080这样的路径测试)
* @param params 请求参数 key为参数名,value为参数值
* @param file 上传文件
*/
public static boolean post ( String path , Map < String , String > params , FormFile file ) throws Exception
{
return post ( path , params , new FormFile []{ file });
}
/**
* 提交数据到服务器
* @param path 上传路径(注:避免使用localhost或127.0.0.1这样的路径测试,因为它会指向手机模拟器,你可以使用http://www.baidu.com或http://192.168.1.10:8080这样的路径测试)
* @param params 请求参数 key为参数名,value为参数值
* @param encode 编码
*/
public static byte [] postFromHttpClient ( String path , Map < String , String > params , String encode ) throws Exception
{
//用于存放请求参数
List < NameValuePair > formparams = new ArrayList < NameValuePair >();
for ( Map . Entry < String , String > entry : params . entrySet ())
{
formparams . add ( new BasicNameValuePair ( entry . getKey (), entry . getValue ()));
}
UrlEncodedFormEntity entity = new UrlEncodedFormEntity ( formparams , encode );
HttpPost httppost = new HttpPost ( path );
httppost . setEntity ( entity );
//看作是浏览器
HttpClient httpclient = new DefaultHttpClient ();
//发送post请求
HttpResponse response = httpclient . execute ( httppost );
return readStream ( response . getEntity (). getContent ());
}
/**
* 发送请求
* @param path 请求路径
* @param params 请求参数 key为参数名称 value为参数值
* @param encode 请求参数的编码
*/
public static byte [] post ( String path , Map < String , String > params , String encode ) throws Exception
{
//String params = "method=save&name="+ URLEncoder.encode("老毕", "UTF-8")+ "&age=28&";//需要发送的参数
StringBuilder parambuilder = new StringBuilder ( "" );
if ( params != null && ! params . isEmpty ())
{
for ( Map . Entry < String , String > entry : params . entrySet ())
{
parambuilder . append ( entry . getKey ()). append ( "=" )
. append ( URLEncoder . encode ( entry . getValue (), encode )). append ( "&" );
}
parambuilder . deleteCharAt ( parambuilder . length ()- 1 );
}
byte [] data = parambuilder . toString (). getBytes ();
URL url = new URL ( path );
HttpURLConnection conn = ( HttpURLConnection ) url . openConnection ();
//设置允许对外发送请求参数
conn . setDoOutput ( true );
//设置不进行缓存
conn . setUseCaches ( false );
conn . setConnectTimeout ( 5 * 1000 );
conn . setRequestMethod ( "POST" );
//下面设置http请求头
conn . setRequestProperty ( "Accept" , "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*" );
conn . setRequestProperty ( "Accept-Language" , "zh-CN" );
conn . setRequestProperty ( "User-Agent" , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)" );
conn . setRequestProperty ( "Content-Type" , "application/x-www-form-urlencoded" );
conn . setRequestProperty ( "Content-Length" , String . valueOf ( data . length ));
conn . setRequestProperty ( "Connection" , "Keep-Alive" );
//发送参数
DataOutputStream outStream = new DataOutputStream ( conn . getOutputStream ());
outStream . write ( data ); //把参数发送出去
outStream . flush ();
outStream . close ();
if ( conn . getResponseCode ()== 200 )
{
return readStream ( conn . getInputStream ());
}
return null ;
}
/**
* 读取流
* @param inStream
* @return 字节数组
* @throws Exception
*/
public static byte [] readStream ( InputStream inStream ) throws Exception
{
ByteArrayOutputStream outSteam = new ByteArrayOutputStream ();
byte [] buffer = new byte [ 1024 ];
int len = - 1 ;
while ( ( len = inStream . read ( buffer )) != - 1 )
{
outSteam . write ( buffer , 0 , len );
}
outSteam . close ();
inStream . close ();
return outSteam . toByteArray ();
}
}
 来自CODE的代码片
SocketHttpRequester.java

实现代码解析:Android使用http协议上传mp3



Android平台调用WebService


WebService的简单介绍:



ps:如果上面看完还是对WebService不是很了解的话,就算了,笔者没弄过WebService,所以也不知道!可怜

而现在我们要做的不是去讨论如果去搭建一个WebService,我们要做的是去获得WebService提供的服务!

然后解析返回的xml数据,把这些数据显示到安卓手机上,简单的小例子如:输入手机号码,获取手机归属地;

查询某地的天气预报,快递单号查询等!


那么我们要怎么去获得这些服务呢?

首先我们去找到提供webService的一些网站:(笔者知道的有以下这两个,如果有免费的站点,欢迎提出羡慕)

①WebXML:http://www.webxml.com.cn/zh_cn/web_services.aspx

也是使用得最多的一个WebService站点,貌似以前是免费的,不过都商业化了,当然是可以试用!不过次数有限!

该网站上提供了16个不同的web服务,可以按照自己的需求,查询自己需要的服务,调用不同的接口即可!


相关使用次数:






②云聚36wu:http://www.36wu.com/Service

同样也提供了很多的服务,很多手机的app都是用的这里的接口,比如彩虹公交,手机天气等

不过,这个也是要收费的=-=,可以试用,不过只能一小时内发送20次请求;哭

点击申请使用,获得key就可以了!两者随便选一个吧!鉴于笔者是学生狗,没什么收入来源,

后期可能会研究下如何搭建自己的WebService,毕竟现在有那么多云平台!敬请期待生气




好了,有了获取服务的站点后,接着就要开始我们app的开发了,由于篇幅关系,这里就简单的演示

下查询号码归属地和天气情况的流程吧,其他的以后根据需求再进行研究!



使用示例:根据手机号码获得归属地与天气情况


step 1:下载第三方jar包:ksoap2 Android:


首先如果想在Android平台上调用WebService需要依赖于第三方类库:ksoap2

而在Android平台上,使用的是ksoap2 Android,一个高效,轻量级的SOAP开发包!

jar包下载地址:https://code.google.com/p/ksoap2-android/wiki/HowToUse?tm=2

鉴于是google的网站,天朝墙了,可能上不去,这里给出百度云的下载链接:

备用胎:3.30版本:http://pan.baidu.com/s/1i3sZksl

           2.54版本:http://pan.baidu.com/s/1jGoTyQi

如果所幸你能进入jar包的下载地址的话,那么你会看到下面的界面:






step 2:记录相关参数:

在开始实际操作之前,我们先要从WebService获取一些信息:分别是:NameSpace(命名空间),SoapAction以及URL

URL就不用说了,其他参数这样找:



然后就可以获取我们需要的SoapAction和namespace了


好了,先把这两个mark下来,接着要测试下自己所在地区的地区码了,在theCityCode:输入所在的城市

下面的id可以不填,因为我们用的是免费用户,接着到达下一个界面,可以看到:


同样的,我们还要做一个号码归属地查询的,所以还要获取号码查询的Service的SoapAction与命名控件:





step 3:开始我们代码的编写了:

效果图:


源码下载:WebService的使用demo


工程核心解析:

一.记得把Android soap2的jar包导入到工程中!不然会提示相关类找不到的!


二.核心代码的编写:


①获取号码所属地的Activity

<a target=_blank id="L1" href="http://blog.csdn.net/coder_pig/article/details/39381479#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;">  1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/coder_pig/article/details/39381479#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;">  2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/coder_pig/article/details/39381479#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;">  3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/coder_pig/article/details/39381479#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;">  4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/coder_pig/article/details/39381479#L5" rel="#L5" style="color: rgb(102, 102, 102); text-decoration: none;">  5</a>
<a target=_blank id="L6" href="http://blog.csdn.net/coder_pig/article/details/39381479#L6" rel="#L6" style="color: rgb(102, 102, 102); text-decoration: none;">  6</a>
<a target=_blank id="L7" href="http://blog.csdn.net/coder_pig/article/details/39381479#L7" rel="#L7" style="color: rgb(102, 102, 102); text-decoration: none;">  7</a>
<a target=_blank id="L8" href="http://blog.csdn.net/coder_pig/article/details/39381479#L8" rel="#L8" style="color: rgb(102, 102, 102); text-decoration: none;">  8</a>
<a target=_blank id="L9" href="http://blog.csdn.net/coder_pig/article/details/39381479#L9" rel="#L9" style="color: rgb(102, 102, 102); text-decoration: none;">  9</a>
<a target=_blank id="L10" href="http://blog.csdn.net/coder_pig/article/details/39381479#L10" rel="#L10" style="color: rgb(102, 102, 102); text-decoration: none;"> 10</a>
<a target=_blank id="L11" href="http://blog.csdn.net/coder_pig/article/details/39381479#L11" rel="#L11" style="color: rgb(102, 102, 102); text-decoration: none;"> 11</a>
<a target=_blank id="L12" href="http://blog.csdn.net/coder_pig/article/details/39381479#L12" rel="#L12" style="color: rgb(102, 102, 102); text-decoration: none;"> 12</a>
<a target=_blank id="L13" href="http://blog.csdn.net/coder_pig/article/details/39381479#L13" rel="#L13" style="color: rgb(102, 102, 102); text-decoration: none;"> 13</a>
<a target=_blank id="L14" href="http://blog.csdn.net/coder_pig/article/details/39381479#L14" rel="#L14" style="color: rgb(102, 102, 102); text-decoration: none;"> 14</a>
<a target=_blank id="L15" href="http://blog.csdn.net/coder_pig/article/details/39381479#L15" rel="#L15" style="color: rgb(102, 102, 102); text-decoration: none;"> 15</a>
<a target=_blank id="L16" href="http://blog.csdn.net/coder_pig/article/details/39381479#L16" rel="#L16" style="color: rgb(102, 102, 102); text-decoration: none;"> 16</a>
<a target=_blank id="L17" href="http://blog.csdn.net/coder_pig/article/details/39381479#L17" rel="#L17" style="color: rgb(102, 102, 102); text-decoration: none;"> 17</a>
<a target=_blank id="L18" href="http://blog.csdn.net/coder_pig/article/details/39381479#L18" rel="#L18" style="color: rgb(102, 102, 102); text-decoration: none;"> 18</a>
<a target=_blank id="L19" href="http://blog.csdn.net/coder_pig/article/details/39381479#L19" rel="#L19" style="color: rgb(102, 102, 102); text-decoration: none;"> 19</a>
<a target=_blank id="L20" href="http://blog.csdn.net/coder_pig/article/details/39381479#L20" rel="#L20" style="color: rgb(102, 102, 102); text-decoration: none;"> 20</a>
<a target=_blank id="L21" href="http://blog.csdn.net/coder_pig/article/details/39381479#L21" rel="#L21" style="color: rgb(102, 102, 102); text-decoration: none;"> 21</a>
<a target=_blank id="L22" href="http://blog.csdn.net/coder_pig/article/details/39381479#L22" rel="#L22" style="color: rgb(102, 102, 102); text-decoration: none;"> 22</a>
<a target=_blank id="L23" href="http://blog.csdn.net/coder_pig/article/details/39381479#L23" rel="#L23" style="color: rgb(102, 102, 102); text-decoration: none;"> 23</a>
<a target=_blank id="L24" href="http://blog.csdn.net/coder_pig/article/details/39381479#L24" rel="#L24" style="color: rgb(102, 102, 102); text-decoration: none;"> 24</a>
<a target=_blank id="L25" href="http://blog.csdn.net/coder_pig/article/details/39381479#L25" rel="#L25" style="color: rgb(102, 102, 102); text-decoration: none;"> 25</a>
<a target=_blank id="L26" href="http://blog.csdn.net/coder_pig/article/details/39381479#L26" rel="#L26" style="color: rgb(102, 102, 102); text-decoration: none;"> 26</a>
<a target=_blank id="L27" href="http://blog.csdn.net/coder_pig/article/details/39381479#L27" rel="#L27" style="color: rgb(102, 102, 102); text-decoration: none;"> 27</a>
<a target=_blank id="L28" href="http://blog.csdn.net/coder_pig/article/details/39381479#L28" rel="#L28" style="color: rgb(102, 102, 102); text-decoration: none;"> 28</a>
<a target=_blank id="L29" href="http://blog.csdn.net/coder_pig/article/details/39381479#L29" rel="#L29" style="color: rgb(102, 102, 102); text-decoration: none;"> 29</a>
<a target=_blank id="L30" href="http://blog.csdn.net/coder_pig/article/details/39381479#L30" rel="#L30" style="color: rgb(102, 102, 102); text-decoration: none;"> 30</a>
<a target=_blank id="L31" href="http://blog.csdn.net/coder_pig/article/details/39381479#L31" rel="#L31" style="color: rgb(102, 102, 102); text-decoration: none;"> 31</a>
<a target=_blank id="L32" href="http://blog.csdn.net/coder_pig/article/details/39381479#L32" rel="#L32" style="color: rgb(102, 102, 102); text-decoration: none;"> 32</a>
<a target=_blank id="L33" href="http://blog.csdn.net/coder_pig/article/details/39381479#L33" rel="#L33" style="color: rgb(102, 102, 102); text-decoration: none;"> 33</a>
<a target=_blank id="L34" href="http://blog.csdn.net/coder_pig/article/details/39381479#L34" rel="#L34" style="color: rgb(102, 102, 102); text-decoration: none;"> 34</a>
<a target=_blank id="L35" href="http://blog.csdn.net/coder_pig/article/details/39381479#L35" rel="#L35" style="color: rgb(102, 102, 102); text-decoration: none;"> 35</a>
<a target=_blank id="L36" href="http://blog.csdn.net/coder_pig/article/details/39381479#L36" rel="#L36" style="color: rgb(102, 102, 102); text-decoration: none;"> 36</a>
<a target=_blank id="L37" href="http://blog.csdn.net/coder_pig/article/details/39381479#L37" rel="#L37" style="color: rgb(102, 102, 102); text-decoration: none;"> 37</a>
<a target=_blank id="L38" href="http://blog.csdn.net/coder_pig/article/details/39381479#L38" rel="#L38" style="color: rgb(102, 102, 102); text-decoration: none;"> 38</a>
<a target=_blank id="L39" href="http://blog.csdn.net/coder_pig/article/details/39381479#L39" rel="#L39" style="color: rgb(102, 102, 102); text-decoration: none;"> 39</a>
<a target=_blank id="L40" href="http://blog.csdn.net/coder_pig/article/details/39381479#L40" rel="#L40" style="color: rgb(102, 102, 102); text-decoration: none;"> 40</a>
<a target=_blank id="L41" href="http://blog.csdn.net/coder_pig/article/details/39381479#L41" rel="#L41" style="color: rgb(102, 102, 102); text-decoration: none;"> 41</a>
<a target=_blank id="L42" href="http://blog.csdn.net/coder_pig/article/details/39381479#L42" rel="#L42" style="color: rgb(102, 102, 102); text-decoration: none;"> 42</a>
<a target=_blank id="L43" href="http://blog.csdn.net/coder_pig/article/details/39381479#L43" rel="#L43" style="color: rgb(102, 102, 102); text-decoration: none;"> 43</a>
<a target=_blank id="L44" href="http://blog.csdn.net/coder_pig/article/details/39381479#L44" rel="#L44" style="color: rgb(102, 102, 102); text-decoration: none;"> 44</a>
<a target=_blank id="L45" href="http://blog.csdn.net/coder_pig/article/details/39381479#L45" rel="#L45" style="color: rgb(102, 102, 102); text-decoration: none;"> 45</a>
<a target=_blank id="L46" href="http://blog.csdn.net/coder_pig/article/details/39381479#L46" rel="#L46" style="color: rgb(102, 102, 102); text-decoration: none;"> 46</a>
<a target=_blank id="L47" href="http://blog.csdn.net/coder_pig/article/details/39381479#L47" rel="#L47" style="color: rgb(102, 102, 102); text-decoration: none;"> 47</a>
<a target=_blank id="L48" href="http://blog.csdn.net/coder_pig/article/details/39381479#L48" rel="#L48" style="color: rgb(102, 102, 102); text-decoration: none;"> 48</a>
<a target=_blank id="L49" href="http://blog.csdn.net/coder_pig/article/details/39381479#L49" rel="#L49" style="color: rgb(102, 102, 102); text-decoration: none;"> 49</a>
<a target=_blank id="L50" href="http://blog.csdn.net/coder_pig/article/details/39381479#L50" rel="#L50" style="color: rgb(102, 102, 102); text-decoration: none;"> 50</a>
<a target=_blank id="L51" href="http://blog.csdn.net/coder_pig/article/details/39381479#L51" rel="#L51" style="color: rgb(102, 102, 102); text-decoration: none;"> 51</a>
<a target=_blank id="L52" href="http://blog.csdn.net/coder_pig/article/details/39381479#L52" rel="#L52" style="color: rgb(102, 102, 102); text-decoration: none;"> 52</a>
<a target=_blank id="L53" href="http://blog.csdn.net/coder_pig/article/details/39381479#L53" rel="#L53" style="color: rgb(102, 102, 102); text-decoration: none;"> 53</a>
<a target=_blank id="L54" href="http://blog.csdn.net/coder_pig/article/details/39381479#L54" rel="#L54" style="color: rgb(102, 102, 102); text-decoration: none;"> 54</a>
<a target=_blank id="L55" href="http://blog.csdn.net/coder_pig/article/details/39381479#L55" rel="#L55" style="color: rgb(102, 102, 102); text-decoration: none;"> 55</a>
<a target=_blank id="L56" href="http://blog.csdn.net/coder_pig/article/details/39381479#L56" rel="#L56" style="color: rgb(102, 102, 102); text-decoration: none;"> 56</a>
<a target=_blank id="L57" href="http://blog.csdn.net/coder_pig/article/details/39381479#L57" rel="#L57" style="color: rgb(102, 102, 102); text-decoration: none;"> 57</a>
<a target=_blank id="L58" href="http://blog.csdn.net/coder_pig/article/details/39381479#L58" rel="#L58" style="color: rgb(102, 102, 102); text-decoration: none;"> 58</a>
<a target=_blank id="L59" href="http://blog.csdn.net/coder_pig/article/details/39381479#L59" rel="#L59" style="color: rgb(102, 102, 102); text-decoration: none;"> 59</a>
<a target=_blank id="L60" href="http://blog.csdn.net/coder_pig/article/details/39381479#L60" rel="#L60" style="color: rgb(102, 102, 102); text-decoration: none;"> 60</a>
<a target=_blank id="L61" href="http://blog.csdn.net/coder_pig/article/details/39381479#L61" rel="#L61" style="color: rgb(102, 102, 102); text-decoration: none;"> 61</a>
<a target=_blank id="L62" href="http://blog.csdn.net/coder_pig/article/details/39381479#L62" rel="#L62" style="color: rgb(102, 102, 102); text-decoration: none;"> 62</a>
<a target=_blank id="L63" href="http://blog.csdn.net/coder_pig/article/details/39381479#L63" rel="#L63" style="color: rgb(102, 102, 102); text-decoration: none;"> 63</a>
<a target=_blank id="L64" href="http://blog.csdn.net/coder_pig/article/details/39381479#L64" rel="#L64" style="color: rgb(102, 102, 102); text-decoration: none;"> 64</a>
<a target=_blank id="L65" href="http://blog.csdn.net/coder_pig/article/details/39381479#L65" rel="#L65" style="color: rgb(102, 102, 102); text-decoration: none;"> 65</a>
<a target=_blank id="L66" href="http://blog.csdn.net/coder_pig/article/details/39381479#L66" rel="#L66" style="color: rgb(102, 102, 102); text-decoration: none;"> 66</a>
<a target=_blank id="L67" href="http://blog.csdn.net/coder_pig/article/details/39381479#L67" rel="#L67" style="color: rgb(102, 102, 102); text-decoration: none;"> 67</a>
<a target=_blank id="L68" href="http://blog.csdn.net/coder_pig/article/details/39381479#L68" rel="#L68" style="color: rgb(102, 102, 102); text-decoration: none;"> 68</a>
<a target=_blank id="L69" href="http://blog.csdn.net/coder_pig/article/details/39381479#L69" rel="#L69" style="color: rgb(102, 102, 102); text-decoration: none;"> 69</a>
<a target=_blank id="L70" href="http://blog.csdn.net/coder_pig/article/details/39381479#L70" rel="#L70" style="color: rgb(102, 102, 102); text-decoration: none;"> 70</a>
<a target=_blank id="L71" href="http://blog.csdn.net/coder_pig/article/details/39381479#L71" rel="#L71" style="color: rgb(102, 102, 102); text-decoration: none;"> 71</a>
<a target=_blank id="L72" href="http://blog.csdn.net/coder_pig/article/details/39381479#L72" rel="#L72" style="color: rgb(102, 102, 102); text-decoration: none;"> 72</a>
<a target=_blank id="L73" href="http://blog.csdn.net/coder_pig/article/details/39381479#L73" rel="#L73" style="color: rgb(102, 102, 102); text-decoration: none;"> 73</a>
<a target=_blank id="L74" href="http://blog.csdn.net/coder_pig/article/details/39381479#L74" rel="#L74" style="color: rgb(102, 102, 102); text-decoration: none;"> 74</a>
<a target=_blank id="L75" href="http://blog.csdn.net/coder_pig/article/details/39381479#L75" rel="#L75" style="color: rgb(102, 102, 102); text-decoration: none;"> 75</a>
<a target=_blank id="L76" href="http://blog.csdn.net/coder_pig/article/details/39381479#L76" rel="#L76" style="color: rgb(102, 102, 102); text-decoration: none;"> 76</a>
<a target=_blank id="L77" href="http://blog.csdn.net/coder_pig/article/details/39381479#L77" rel="#L77" style="color: rgb(102, 102, 102); text-decoration: none;"> 77</a>
<a target=_blank id="L78" href="http://blog.csdn.net/coder_pig/article/details/39381479#L78" rel="#L78" style="color: rgb(102, 102, 102); text-decoration: none;"> 78</a>
<a target=_blank id="L79" href="http://blog.csdn.net/coder_pig/article/details/39381479#L79" rel="#L79" style="color: rgb(102, 102, 102); text-decoration: none;"> 79</a>
<a target=_blank id="L80" href="http://blog.csdn.net/coder_pig/article/details/39381479#L80" rel="#L80" style="color: rgb(102, 102, 102); text-decoration: none;"> 80</a>
<a target=_blank id="L81" href="http://blog.csdn.net/coder_pig/article/details/39381479#L81" rel="#L81" style="color: rgb(102, 102, 102); text-decoration: none;"> 81</a>
<a target=_blank id="L82" href="http://blog.csdn.net/coder_pig/article/details/39381479#L82" rel="#L82" style="color: rgb(102, 102, 102); text-decoration: none;"> 82</a>
<a target=_blank id="L83" href="http://blog.csdn.net/coder_pig/article/details/39381479#L83" rel="#L83" style="color: rgb(102, 102, 102); text-decoration: none;"> 83</a>
<a target=_blank id="L84" href="http://blog.csdn.net/coder_pig/article/details/39381479#L84" rel="#L84" style="color: rgb(102, 102, 102); text-decoration: none;"> 84</a>
<a target=_blank id="L85" href="http://blog.csdn.net/coder_pig/article/details/39381479#L85" rel="#L85" style="color: rgb(102, 102, 102); text-decoration: none;"> 85</a>
<a target=_blank id="L86" href="http://blog.csdn.net/coder_pig/article/details/39381479#L86" rel="#L86" style="color: rgb(102, 102, 102); text-decoration: none;"> 86</a>
<a target=_blank id="L87" href="http://blog.csdn.net/coder_pig/article/details/39381479#L87" rel="#L87" style="color: rgb(102, 102, 102); text-decoration: none;"> 87</a>
<a target=_blank id="L88" href="http://blog.csdn.net/coder_pig/article/details/39381479#L88" rel="#L88" style="color: rgb(102, 102, 102); text-decoration: none;"> 88</a>
<a target=_blank id="L89" href="http://blog.csdn.net/coder_pig/article/details/39381479#L89" rel="#L89" style="color: rgb(102, 102, 102); text-decoration: none;"> 89</a>
<a target=_blank id="L90" href="http://blog.csdn.net/coder_pig/article/details/39381479#L90" rel="#L90" style="color: rgb(102, 102, 102); text-decoration: none;"> 90</a>
<a target=_blank id="L91" href="http://blog.csdn.net/coder_pig/article/details/39381479#L91" rel="#L91" style="color: rgb(102, 102, 102); text-decoration: none;"> 91</a>
<a target=_blank id="L92" href="http://blog.csdn.net/coder_pig/article/details/39381479#L92" rel="#L92" style="color: rgb(102, 102, 102); text-decoration: none;"> 92</a>
<a target=_blank id="L93" href="http://blog.csdn.net/coder_pig/article/details/39381479#L93" rel="#L93" style="color: rgb(102, 102, 102); text-decoration: none;"> 93</a>
<a target=_blank id="L94" href="http://blog.csdn.net/coder_pig/article/details/39381479#L94" rel="#L94" style="color: rgb(102, 102, 102); text-decoration: none;"> 94</a>
<a target=_blank id="L95" href="http://blog.csdn.net/coder_pig/article/details/39381479#L95" rel="#L95" style="color: rgb(102, 102, 102); text-decoration: none;"> 95</a>
<a target=_blank id="L96" href="http://blog.csdn.net/coder_pig/article/details/39381479#L96" rel="#L96" style="color: rgb(102, 102, 102); text-decoration: none;"> 96</a>
<a target=_blank id="L97" href="http://blog.csdn.net/coder_pig/article/details/39381479#L97" rel="#L97" style="color: rgb(102, 102, 102); text-decoration: none;"> 97</a>
<a target=_blank id="L98" href="http://blog.csdn.net/coder_pig/article/details/39381479#L98" rel="#L98" style="color: rgb(102, 102, 102); text-decoration: none;"> 98</a>
<a target=_blank id="L99" href="http://blog.csdn.net/coder_pig/article/details/39381479#L99" rel="#L99" style="color: rgb(102, 102, 102); text-decoration: none;"> 99</a>
           
           
package com . jay . example . webserviceusedemo ;
import org.ksoap2.SoapEnvelope ;
import org.ksoap2.serialization.SoapObject ;
import org.ksoap2.serialization.SoapSerializationEnvelope ;
import org.ksoap2.transport.HttpTransportSE ;
import android.app.Activity ;
import android.os.Bundle ;
import android.os.Handler ;
import android.os.Message ;
import android.view.View ;
import android.view.View.OnClickListener ;
import android.widget.Button ;
import android.widget.EditText ;
import android.widget.TextView ;
import android.widget.Toast ;
public class NumberActivity extends Activity {
//定义获取手机信息的SoapAction与命名空间,作为常量
static final String AddressnameSpace = "http://WebXml.com.cn/" ;
static final String Addressurl = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx" ;
static final String Addressmethod = "getMobileCodeInfo" ;
static final String AddresssoapAction = "http://WebXml.com.cn/getMobileCodeInfo" ;
//定义相关变量:
private Button btnn ;
private TextView textshown ;
private EditText editnum ;
private String number ;
private String result ;
//定义一个Handler类,用来更新TextView显示内容的
Handler handler = new Handler ()
{
public void handleMessage ( Message msg )
{
System . out . println ( "查询后的归属地信息:" + result );
textshown . setText ( result );
Toast . makeText ( NumberActivity . this , "获取天气信息成功" , Toast . LENGTH_SHORT ). show ();
};
};
protected void onCreate ( Bundle savedInstanceState )
{
super . onCreate ( savedInstanceState );
setContentView ( R . layout . activity_number );
btnn = ( Button ) findViewById ( R . id . btnn );
editnum = ( EditText ) findViewById ( R . id . editnum );
textshown = ( TextView ) findViewById ( R . id . textshown );
btnn . setOnClickListener ( new OnClickListener () {
@Override
public void onClick ( View v ) {
new Thread ( new Runnable () {
public void run () {
getland ();
}
}). start ();
}
});
}
public void getland ()
{
SoapObject soapObject = new SoapObject ( AddressnameSpace , Addressmethod );
soapObject . addProperty ( "mobileCode" , editnum . getText (). toString ());
soapObject . addProperty ( "userid" , "" );
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope ( SoapEnvelope . VER11 );
envelope . bodyOut = soapObject ;
envelope . dotNet = true ;
envelope . setOutputSoapObject ( soapObject );
HttpTransportSE httpTransportSE = new HttpTransportSE ( Addressurl );
// System.out.println("号码信息设置完毕,准备开启服务");
try
{
httpTransportSE . call ( AddresssoapAction , envelope );
//System.out.println("调用WebService服务成功");
} catch ( Exception e ){
e . printStackTrace ();
//System.out.println("调用WebService服务失败");
}
//获得服务返回的数据,并且开始解析
SoapObject object = ( SoapObject ) envelope . bodyIn ; //System.out.println("获得服务数据");
result = object . getProperty ( 0 ). toString (); //System.out.println("获取信息完毕,向主线程发信息");
handler . sendEmptyMessage ( 0 );
//System.out.println("发送完毕,textview显示天气信息");
}
}
 来自CODE的代码片
NumberActivity.java

②获取某城市(这里是江门)的天气情况

<a target=_blank id="L1" href="http://blog.csdn.net/coder_pig/article/details/39381479#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;">   1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/coder_pig/article/details/39381479#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;">   2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/coder_pig/article/details/39381479#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;">   3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/coder_pig/article/details/39381479#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;">   4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/coder_pig/article/details/39381479#L5" rel="#L5" style="color: rgb(102, 102, 102); text-decoration: none;">   5</a>
<a target=_blank id="L6" href="http://blog.csdn.net/coder_pig/article/details/39381479#L6" rel="#L6" style="color: rgb(102, 102, 102); text-decoration: none;">   6</a>
<a target=_blank id="L7" href="http://blog.csdn.net/coder_pig/article/details/39381479#L7" rel="#L7" style="color: rgb(102, 102, 102); text-decoration: none;">   7</a>
<a target=_blank id="L8" href="http://blog.csdn.net/coder_pig/article/details/39381479#L8" rel="#L8" style="color: rgb(102, 102, 102); text-decoration: none;">   8</a>
<a target=_blank id="L9" href="http://blog.csdn.net/coder_pig/article/details/39381479#L9" rel="#L9" style="color: rgb(102, 102, 102); text-decoration: none;">   9</a>
<a target=_blank id="L10" href="http://blog.csdn.net/coder_pig/article/details/39381479#L10" rel="#L10" style="color: rgb(102, 102, 102); text-decoration: none;">  10</a>
<a target=_blank id="L11" href="http://blog.csdn.net/coder_pig/article/details/39381479#L11" rel="#L11" style="color: rgb(102, 102, 102); text-decoration: none;">  11</a>
<a target=_blank id="L12" href="http://blog.csdn.net/coder_pig/article/details/39381479#L12" rel="#L12" style="color: rgb(102, 102, 102); text-decoration: none;">  12</a>
<a target=_blank id="L13" href="http://blog.csdn.net/coder_pig/article/details/39381479#L13" rel="#L13" style="color: rgb(102, 102, 102); text-decoration: none;">  13</a>
<a target=_blank id="L14" href="http://blog.csdn.net/coder_pig/article/details/39381479#L14" rel="#L14" style="color: rgb(102, 102, 102); text-decoration: none;">  14</a>
<a target=_blank id="L15" href="http://blog.csdn.net/coder_pig/article/details/39381479#L15" rel="#L15" style="color: rgb(102, 102, 102); text-decoration: none;">  15</a>
<a target=_blank id="L16" href="http://blog.csdn.net/coder_pig/article/details/39381479#L16" rel="#L16" style="color: rgb(102, 102, 102); text-decoration: none;">  16</a>
<a target=_blank id="L17" href="http://blog.csdn.net/coder_pig/article/details/39381479#L17" rel="#L17" style="color: rgb(102, 102, 102); text-decoration: none;">  17</a>
<a target=_blank id="L18" href="http://blog.csdn.net/coder_pig/article/details/39381479#L18" rel="#L18" style="color: rgb(102, 102, 102); text-decoration: none;">  18</a>
<a target=_blank id="L19" href="http://blog.csdn.net/coder_pig/article/details/39381479#L19" rel="#L19" style="color: rgb(102, 102, 102); text-decoration: none;">  19</a>
<a target=_blank id="L20" href="http://blog.csdn.net/coder_pig/article/details/39381479#L20" rel="#L20" style="color: rgb(102, 102, 102); text-decoration: none;">  20</a>
<a target=_blank id="L21" href="http://blog.csdn.net/coder_pig/article/details/39381479#L21" rel="#L21" style="color: rgb(102, 102, 102); text-decoration: none;">  21</a>
<a target=_blank id="L22" href="http://blog.csdn.net/coder_pig/article/details/39381479#L22" rel="#L22" style="color: rgb(102, 102, 102); text-decoration: none;">  22</a>
<a target=_blank id="L23" href="http://blog.csdn.net/coder_pig/article/details/39381479#L23" rel="#L23" style="color: rgb(102, 102, 102); text-decoration: none;">  23</a>
<a target=_blank id="L24" href="http://blog.csdn.net/coder_pig/article/details/39381479#L24" rel="#L24" style="color: rgb(102, 102, 102); text-decoration: none;">  24</a>
<a target=_blank id="L25" href="http://blog.csdn.net/coder_pig/article/details/39381479#L25" rel="#L25" style="color: rgb(102, 102, 102); text-decoration: none;">  25</a>
<a target=_blank id="L26" href="http://blog.csdn.net/coder_pig/article/details/39381479#L26" rel="#L26" style="color: rgb(102, 102, 102); text-decoration: none;">  26</a>
<a target=_blank id="L27" href="http://blog.csdn.net/coder_pig/article/details/39381479#L27" rel="#L27" style="color: rgb(102, 102, 102); text-decoration: none;">  27</a>
<a target=_blank id="L28" href="http://blog.csdn.net/coder_pig/article/details/39381479#L28" rel="#L28" style="color: rgb(102, 102, 102); text-decoration: none;">  28</a>
<a target=_blank id="L29" href="http://blog.csdn.net/coder_pig/article/details/39381479#L29" rel="#L29" style="color: rgb(102, 102, 102); text-decoration: none;">  29</a>
<a target=_blank id="L30" href="http://blog.csdn.net/coder_pig/article/details/39381479#L30" rel="#L30" style="color: rgb(102, 102, 102); text-decoration: none;">  30</a>
<a target=_blank id="L31" href="http://blog.csdn.net/coder_pig/article/details/39381479#L31" rel="#L31" style="color: rgb(102, 102, 102); text-decoration: none;">  31</a>
<a target=_blank id="L32" href="http://blog.csdn.net/coder_pig/article/details/39381479#L32" rel="#L32" style="color: rgb(102, 102, 102); text-decoration: none;">  32</a>
<a target=_blank id="L33" href="http://blog.csdn.net/coder_pig/article/details/39381479#L33" rel="#L33" style="color: rgb(102, 102, 102); text-decoration: none;">  33</a>
<a target=_blank id="L34" href="http://blog.csdn.net/coder_pig/article/details/39381479#L34" rel="#L34" style="color: rgb(102, 102, 102); text-decoration: none;">  34</a>
<a target=_blank id="L35" href="http://blog.csdn.net/coder_pig/article/details/39381479#L35" rel="#L35" style="color: rgb(102, 102, 102); text-decoration: none;">  35</a>
<a target=_blank id="L36" href="http://blog.csdn.net/coder_pig/article/details/39381479#L36" rel="#L36" style="color: rgb(102, 102, 102); text-decoration: none;">  36</a>
<a target=_blank id="L37" href="http://blog.csdn.net/coder_pig/article/details/39381479#L37" rel="#L37" style="color: rgb(102, 102, 102); text-decoration: none;">  37</a>
<a target=_blank id="L38" href="http://blog.csdn.net/coder_pig/article/details/39381479#L38" rel="#L38" style="color: rgb(102, 102, 102); text-decoration: none;">  38</a>
<a target=_blank id="L39" href="http://blog.csdn.net/coder_pig/article/details/39381479#L39" rel="#L39" style="color: rgb(102, 102, 102); text-decoration: none;">  39</a>
<a target=_blank id="L40" href="http://blog.csdn.net/coder_pig/article/details/39381479#L40" rel="#L40" style="color: rgb(102, 102, 102); text-decoration: none;">  40</a>
<a target=_blank id="L41" href="http://blog.csdn.net/coder_pig/article/details/39381479#L41" rel="#L41" style="color: rgb(102, 102, 102); text-decoration: none;">  41</a>
<a target=_blank id="L42" href="http://blog.csdn.net/coder_pig/article/details/39381479#L42" rel="#L42" style="color: rgb(102, 102, 102); text-decoration: none;">  42</a>
<a target=_blank id="L43" href="http://blog.csdn.net/coder_pig/article/details/39381479#L43" rel="#L43" style="color: rgb(102, 102, 102); text-decoration: none;">  43</a>
<a target=_blank id="L44" href="http://blog.csdn.net/coder_pig/article/details/39381479#L44" rel="#L44" style="color: rgb(102, 102, 102); text-decoration: none;">  44</a>
<a target=_blank id="L45" href="http://blog.csdn.net/coder_pig/article/details/39381479#L45" rel="#L45" style="color: rgb(102, 102, 102); text-decoration: none;">  45</a>
<a target=_blank id="L46" href="http://blog.csdn.net/coder_pig/article/details/39381479#L46" rel="#L46" style="color: rgb(102, 102, 102); text-decoration: none;">  46</a>
<a target=_blank id="L47" href="http://blog.csdn.net/coder_pig/article/details/39381479#L47" rel="#L47" style="color: rgb(102, 102, 102); text-decoration: none;">  47</a>
<a target=_blank id="L48" href="http://blog.csdn.net/coder_pig/article/details/39381479#L48" rel="#L48" style="color: rgb(102, 102, 102); text-decoration: none;">  48</a>
<a target=_blank id="L49" href="http://blog.csdn.net/coder_pig/article/details/39381479#L49" rel="#L49" style="color: rgb(102, 102, 102); text-decoration: none;">  49</a>
<a target=_blank id="L50" href="http://blog.csdn.net/coder_pig/article/details/39381479#L50" rel="#L50" style="color: rgb(102, 102, 102); text-decoration: none;">  50</a>
<a target=_blank id="L51" href="http://blog.csdn.net/coder_pig/article/details/39381479#L51" rel="#L51" style="color: rgb(102, 102, 102); text-decoration: none;">  51</a>
<a target=_blank id="L52" href="http://blog.csdn.net/coder_pig/article/details/39381479#L52" rel="#L52" style="color: rgb(102, 102, 102); text-decoration: none;">  52</a>
<a target=_blank id="L53" href="http://blog.csdn.net/coder_pig/article/details/39381479#L53" rel="#L53" style="color: rgb(102, 102, 102); text-decoration: none;">  53</a>
<a target=_blank id="L54" href="http://blog.csdn.net/coder_pig/article/details/39381479#L54" rel="#L54" style="color: rgb(102, 102, 102); text-decoration: none;">  54</a>
<a target=_blank id="L55" href="http://blog.csdn.net/coder_pig/article/details/39381479#L55" rel="#L55" style="color: rgb(102, 102, 102); text-decoration: none;">  55</a>
<a target=_blank id="L56" href="http://blog.csdn.net/coder_pig/article/details/39381479#L56" rel="#L56" style="color: rgb(102, 102, 102); text-decoration: none;">  56</a>
<a target=_blank id="L57" href="http://blog.csdn.net/coder_pig/article/details/39381479#L57" rel="#L57" style="color: rgb(102, 102, 102); text-decoration: none;">  57</a>
<a target=_blank id="L58" href="http://blog.csdn.net/coder_pig/article/details/39381479#L58" rel="#L58" style="color: rgb(102, 102, 102); text-decoration: none;">  58</a>
<a target=_blank id="L59" href="http://blog.csdn.net/coder_pig/article/details/39381479#L59" rel="#L59" style="color: rgb(102, 102, 102); text-decoration: none;">  59</a>
<a target=_blank id="L60" href="http://blog.csdn.net/coder_pig/article/details/39381479#L60" rel="#L60" style="color: rgb(102, 102, 102); text-decoration: none;">  60</a>
<a target=_blank id="L61" href="http://blog.csdn.net/coder_pig/article/details/39381479#L61" rel="#L61" style="color: rgb(102, 102, 102); text-decoration: none;">  61</a>
<a target=_blank id="L62" href="http://blog.csdn.net/coder_pig/article/details/39381479#L62" rel="#L62" style="color: rgb(102, 102, 102); text-decoration: none;">  62</a>
<a target=_blank id="L63" href="http://blog.csdn.net/coder_pig/article/details/39381479#L63" rel="#L63" style="color: rgb(102, 102, 102); text-decoration: none;">  63</a>
<a target=_blank id="L64" href="http://blog.csdn.net/coder_pig/article/details/39381479#L64" rel="#L64" style="color: rgb(102, 102, 102); text-decoration: none;">  64</a>
<a target=_blank id="L65" href="http://blog.csdn.net/coder_pig/article/details/39381479#L65" rel="#L65" style="color: rgb(102, 102, 102); text-decoration: none;">  65</a>
<a target=_blank id="L66" href="http://blog.csdn.net/coder_pig/article/details/39381479#L66" rel="#L66" style="color: rgb(102, 102, 102); text-decoration: none;">  66</a>
<a target=_blank id="L67" href="http://blog.csdn.net/coder_pig/article/details/39381479#L67" rel="#L67" style="color: rgb(102, 102, 102); text-decoration: none;">  67</a>
<a target=_blank id="L68" href="http://blog.csdn.net/coder_pig/article/details/39381479#L68" rel="#L68" style="color: rgb(102, 102, 102); text-decoration: none;">  68</a>
<a target=_blank id="L69" href="http://blog.csdn.net/coder_pig/article/details/39381479#L69" rel="#L69" style="color: rgb(102, 102, 102); text-decoration: none;">  69</a>
<a target=_blank id="L70" href="http://blog.csdn.net/coder_pig/article/details/39381479#L70" rel="#L70" style="color: rgb(102, 102, 102); text-decoration: none;">  70</a>
<a target=_blank id="L71" href="http://blog.csdn.net/coder_pig/article/details/39381479#L71" rel="#L71" style="color: rgb(102, 102, 102); text-decoration: none;">  71</a>
<a target=_blank id="L72" href="http://blog.csdn.net/coder_pig/article/details/39381479#L72" rel="#L72" style="color: rgb(102, 102, 102); text-decoration: none;">  72</a>
<a target=_blank id="L73" href="http://blog.csdn.net/coder_pig/article/details/39381479#L73" rel="#L73" style="color: rgb(102, 102, 102); text-decoration: none;">  73</a>
<a target=_blank id="L74" href="http://blog.csdn.net/coder_pig/article/details/39381479#L74" rel="#L74" style="color: rgb(102, 102, 102); text-decoration: none;">  74</a>
<a target=_blank id="L75" href="http://blog.csdn.net/coder_pig/article/details/39381479#L75" rel="#L75" style="color: rgb(102, 102, 102); text-decoration: none;">  75</a>
<a target=_blank id="L76" href="http://blog.csdn.net/coder_pig/article/details/39381479#L76" rel="#L76" style="color: rgb(102, 102, 102); text-decoration: none;">  76</a>
<a target=_blank id="L77" href="http://blog.csdn.net/coder_pig/article/details/39381479#L77" rel="#L77" style="color: rgb(102, 102, 102); text-decoration: none;">  77</a>
<a target=_blank id="L78" href="http://blog.csdn.net/coder_pig/article/details/39381479#L78" rel="#L78" style="color: rgb(102, 102, 102); text-decoration: none;">  78</a>
<a target=_blank id="L79" href="http://blog.csdn.net/coder_pig/article/details/39381479#L79" rel="#L79" style="color: rgb(102, 102, 102); text-decoration: none;">  79</a>
<a target=_blank id="L80" href="http://blog.csdn.net/coder_pig/article/details/39381479#L80" rel="#L80" style="color: rgb(102, 102, 102); text-decoration: none;">  80</a>
<a target=_blank id="L81" href="http://blog.csdn.net/coder_pig/article/details/39381479#L81" rel="#L81" style="color: rgb(102, 102, 102); text-decoration: none;">  81</a>
<a target=_blank id="L82" href="http://blog.csdn.net/coder_pig/article/details/39381479#L82" rel="#L82" style="color: rgb(102, 102, 102); text-decoration: none;">  82</a>
<a target=_blank id="L83" href="http://blog.csdn.net/coder_pig/article/details/39381479#L83" rel="#L83" style="color: rgb(102, 102, 102); text-decoration: none;">  83</a>
<a target=_blank id="L84" href="http://blog.csdn.net/coder_pig/article/details/39381479#L84" rel="#L84" style="color: rgb(102, 102, 102); text-decoration: none;">  84</a>
<a target=_blank id="L85" href="http://blog.csdn.net/coder_pig/article/details/39381479#L85" rel="#L85" style="color: rgb(102, 102, 102); text-decoration: none;">  85</a>
<a target=_blank id="L86" href="http://blog.csdn.net/coder_pig/article/details/39381479#L86" rel="#L86" style="color: rgb(102, 102, 102); text-decoration: none;">  86</a>
<a target=_blank id="L87" href="http://blog.csdn.net/coder_pig/article/details/39381479#L87" rel="#L87" style="color: rgb(102, 102, 102); text-decoration: none;">  87</a>
<a target=_blank id="L88" href="http://blog.csdn.net/coder_pig/article/details/39381479#L88" rel="#L88" style="color: rgb(102, 102, 102); text-decoration: none;">  88</a>
<a target=_blank id="L89" href="http://blog.csdn.net/coder_pig/article/details/39381479#L89" rel="#L89" style="color: rgb(102, 102, 102); text-decoration: none;">  89</a>
<a target=_blank id="L90" href="http://blog.csdn.net/coder_pig/article/details/39381479#L90" rel="#L90" style="color: rgb(102, 102, 102); text-decoration: none;">  90</a>
<a target=_blank id="L91" href="http://blog.csdn.net/coder_pig/article/details/39381479#L91" rel="#L91" style="color: rgb(102, 102, 102); text-decoration: none;">  91</a>
<a target=_blank id="L92" href="http://blog.csdn.net/coder_pig/article/details/39381479#L92" rel="#L92" style="color: rgb(102, 102, 102); text-decoration: none;">  92</a>
<a target=_blank id="L93" href="http://blog.csdn.net/coder_pig/article/details/39381479#L93" rel="#L93" style="color: rgb(102, 102, 102); text-decoration: none;">  93</a>
<a target=_blank id="L94" href="http://blog.csdn.net/coder_pig/article/details/39381479#L94" rel="#L94" style="color: rgb(102, 102, 102); text-decoration: none;">  94</a>
<a target=_blank id="L95" href="http://blog.csdn.net/coder_pig/article/details/39381479#L95" rel="#L95" style="color: rgb(102, 102, 102); text-decoration: none;">  95</a>
<a target=_blank id="L96" href="http://blog.csdn.net/coder_pig/article/details/39381479#L96" rel="#L96" style="color: rgb(102, 102, 102); text-decoration: none;">  96</a>
<a target=_blank id="L97" href="http://blog.csdn.net/coder_pig/article/details/39381479#L97" rel="#L97" style="color: rgb(102, 102, 102); text-decoration: none;">  97</a>
<a target=_blank id="L98" href="http://blog.csdn.net/coder_pig/article/details/39381479#L98" rel="#L98" style="color: rgb(102, 102, 102); text-decoration: none;">  98</a>
<a target=_blank id="L99" href="http://blog.csdn.net/coder_pig/article/details/39381479#L99" rel="#L99" style="color: rgb(102, 102, 102); text-decoration: none;">  99</a>
<a target=_blank id="L100" href="http://blog.csdn.net/coder_pig/article/details/39381479#L100" rel="#L100" style="color: rgb(102, 102, 102); text-decoration: none;"> 100</a>
<a target=_blank id="L101" href="http://blog.csdn.net/coder_pig/article/details/39381479#L101" rel="#L101" style="color: rgb(102, 102, 102); text-decoration: none;"> 101</a>
           
           
package com . jay . example . webserviceusedemo ;
import org.ksoap2.SoapEnvelope ;
import org.ksoap2.serialization.SoapObject ;
import org.ksoap2.serialization.SoapSerializationEnvelope ;
import org.ksoap2.transport.HttpTransportSE ;
import org.ksoap2.transport.HttpsTransportSE ;
import android.app.Activity ;
import android.os.Bundle ;
import android.os.Handler ;
import android.os.Message ;
import android.view.View ;
import android.view.View.OnClickListener ;
import android.widget.Button ;
import android.widget.TextView ;
import android.widget.Toast ;
public class WetherActivity extends Activity {
//定义获取天气信息的SoapAction与命名空间,作为常量
static final String WeathernameSpace = "http://www.36wu.com/" ;
static final String Weatherurl = "http://web.36wu.com/WeatherService.asmx" ;
static final String Weathermethod = "GetWeather" ;
static final String WeathersoapAction = "http://www.36wu.com/GetWeather" ;
//定义相关变量:
private Button btnw ;
private TextView textwether ;
private String wether ;
//定义一个Handler类,用来更新TextView显示内容的
Handler handler = new Handler ()
{
public void handleMessage ( Message msg )
{
System . out . println ( "更新后的天气信息:" + wether );
textwether . setText ( wether );
Toast . makeText ( WetherActivity . this , "获取天气信息成功" , Toast . LENGTH_SHORT ). show ();
};
};
protected void onCreate ( Bundle savedInstanceState )
{
super . onCreate ( savedInstanceState );
setContentView ( R . layout . activity_wether );
btnw = ( Button ) findViewById ( R . id . btnw );
textwether = ( TextView ) findViewById ( R . id . textshoww );
btnw . setOnClickListener ( new OnClickListener () {
@Override
public void onClick ( View v ) {
//因为不允许在主线程中进行网络操作,所以需要另外开辟一个线程
new Thread ()
{
@Override
public void run () {
getWether ();
}
}. start ();
}
});
}
//定义一个获取天气的方法
public void getWether ()
{
SoapObject soapObject = new SoapObject ( WeathernameSpace , Weathermethod );
soapObject . addProperty ( "district" , "2408" );
soapObject . addProperty ( "authkey" , "dd77aaf5254d48a3a3eaab2f207b027a" );
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope ( SoapEnvelope . VER11 );
envelope . bodyOut = soapObject ;
envelope . dotNet = true ;
envelope . setOutputSoapObject ( soapObject );
HttpTransportSE httpTransportSE = new HttpTransportSE ( Weatherurl );
System . out . println ( "天气服务设置完毕,准备开启服务" );
try
{
httpTransportSE . call ( WeathersoapAction , envelope );
System . out . println ( "调用WebService服务成功" );
} catch ( Exception e ){
e . printStackTrace ();
System . out . println ( "调用WebService服务失败" );
}
//获得服务返回的数据,并且开始解析
SoapObject object = ( SoapObject ) envelope . bodyIn ; System . out . println ( "获得服务数据" );
wether = object . getProperty ( 0 ). toString (); System . out . println ( "获取信息完毕,向主线程发信息" );
handler . sendEmptyMessage ( 0 );
System . out . println ( "发送完毕,textview显示天气信息" );
}
}
 来自CODE的代码片
WetherActivity.java


ps:相信细心的朋友都会发现这里用了两个不同的webservice站点,一个是webxml一个是36wu;

其实呢一开始都是用的webxml,但是,笔者的运气真是背,刚好遇到了天气查询服务维护,


笔者即使使用申请使用id,也是返回"...现在不支持普通用户,...申请id",所以就用了36wu的!




其实都差不多,改起来也是比较简单的,根据站点的soap改下相关参数即可:







另外,别忘了,添加Internet权限哦!在AndroidManifest.xml文件中添加下述权限:

<uses-permission android:name="android.permission.INTERNET"/>




总结:

本文的内容还是比较多的,但是都不难,很多只要我们大概明白原理,然后到用的时候

知道怎么去改就可以了!笔者也写了几天才写完的!如果你能坚持看完的话,相信你会收获

很多,另外文章篇幅较长,希望读者可以耐心读完,写这么详细是想照顾一些和我一样的迷途

小菜鸟,望体谅,好了,本节就到这里!谢谢你们的支持大笑另外,现在大部分的WebService站点

都是要收费的,可怜笔者穷屌买不起会员,只能试用试用了,以后进公司就不用自己给钱了!羡慕

不过大牛说可以自己搭建个WebService服务器,以后有时间会尝试弄一个,然后把经验分享

给大家的,生气毕竟现在各种云,阿里云,腾讯云,搜狐云景...好了,最后贴下申请试用key的流程吧!

有兴趣的再看吧!



==============可以不看==================================================

附录:

一.webxml申请试用id:

注册账号


登陆账号,查看自己的key


点击我的web服务,可以看到相关的服务,这里笔者开通了天气查询的,试用五天:


这里的是要给钱的,所以说起其它的6个服务是免费的,比如我们的号码归属地查询...

接着我们来到weather服务那里,输入地区编码以及我们的key,就可以查询天气了:


噔噔噔,接着就可以看到信息了,我们就可以在我们的应用中解析这些数据了~!





二.36wu的key的申请与使用流程:

闭嘴相比webxml就抠门很多了,人家起码可以使用5个服务,一个服务5天,5*5=25

而36wu的key只能用一天,大哭也不能说扣吧,商家都要赚钱!一天就一天,也可以爽一下啦!

同样是需要申请key的


接着会收到一条短信=-=,把key复制下即可


接着同样来到wetherservice的界面:输入地区码和key


返回结果,接着就到我们的客户端进行处理了:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值