2012-05-15 23 views
0

我想從我的手機發送數據到HttpPost與MySQL,但我沒有任何服務器設置,所以我想知道如果我能看到我準確發送什麼,以及它的樣子。我對JSON和那些看起來很熟悉的人有點熟悉。所以我很好奇爲了調試的目的我會發送給mysql。android測試用於調試目的的HttpPost字符串

public void sendDataDetail(View v){ 
    String name = nameText.getText().toString(); 

    if(name.length()>0){ 
     Log.w(TAG, name); 
     HttpClient httpclient = new DefaultHttpClient(); 
     HttpPost httppost = new HttpPost("http://site/post.php"); 
     Log.w(TAG, "After HttpPost"); 
     try{ 
      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); 
      Log.w(TAG, "After list"); 
      nameValuePairs.add(new BasicNameValuePair("location","Los Angeles")); 
      Log.w(TAG, "After location"); 
      nameValuePairs.add(new BasicNameValuePair("item_name",name)); 
      Log.w(TAG, "After item"); 
      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
      Log.w(TAG, "After nameValuePairs"); 
      httpclient.execute(httppost); 
      nameText.setText(""); // clear text box, but this should be back to front page 
     }catch(ClientProtocolException e){ 
      Log.w(TAG, e.getMessage()); 
     }catch(IOException e){ 
      Log.w(TAG, e.getMessage()); 

     } 
    } 
} 

正如你可以看到我有一堆日誌來測試它是否通過每一行(不知道這是否甚至必要= \)。我在想,如果我能看到httppost是什麼樣子,但它好像如果我做這樣的事情

Log.w(TAG, httppost); 

我得到的錯誤,它不會工作。

任何關於如何測試我發送給mysql進行調試的建議?

在此先感謝

回答

1

根據HttpClient的您正在使用的版本,有將要開啓2個關鍵記錄儀的各種方式:

httpclient.wire.header httpclient.wire

在一種類型的客戶機,可以使用Java系統屬性來激活相應的記錄器幾乎總是使用由HttpClient的(頭&絲)DEBUG級記錄的...

0上面的

不適用於所有情況。例如,在Android上,我使用client ,爲了激活WIRE和HEADERS的日誌記錄,我必須重新編譯第三方軟件包,更改class = ch.boye.httpclientandroidlib.androidextra.HttpClientAndroidLog(Log DEBUG ON | OFF )

既記錄儀的logcat的

樣品板開啓給人什麼的HTTP的幕後發生的完整視圖...

I/PicasaAlbumService(2218): Starting PHOTOService.onHandleIntent com.b2bpo.media.action.ALBUMLIST 
I/ActivityManager( 163): Displayed com.b2bpo.media/.ApplyGeoActivity: +1s349ms (total +5s944ms) 
D/dalvikvm(2218): GC_CONCURRENT freed 292K, 44% free 3625K/6407K, external 387K/519K, paused 2ms+3ms 
D/class ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient(2218): Attempt 1 to execute request 
D/class ch.boye.httpclientandroidlib.impl.conn.DefaultClientConnection(2218): Sending request: GET /data/feed/api/user/default?fields=entry%2Ftitle%2Centry%2Fl 
ink%5B%40rel%3D%22http%3A%2F%2Fschemas.google.com%2Fg%2F2005%23feed%22%5D&start-index=1&max-results=10&alt=json HTTP/1.1 
D/ch.boye.httpclientandroidlib.wire(2218): >> "GET /data/feed/api/user/default?fields=entry%2Ftitle%2Centry%2Flink%5B%40rel%3D%22http%3A%2F%2Fschemas.google.co 
m%2Fg%2F2005%23feed%22%5D&start-index=1&max-results=10&alt=json HTTP/1.1[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): >> "GData-Version: 2[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): >> "Host: picasaweb.google.com[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): >> "Connection: Keep-Alive[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): >> "Authorization: OAuth null[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): >> "[\r][\n]" 
D/ch.boye.httpclientandroidlib.headers(2218): >> GET /data/feed/api/user/default?fields=entry%2Ftitle%2Centry%2Flink%5B%40rel%3D%22http%3A%2F%2Fschemas.google. 
com%2Fg%2F2005%23feed%22%5D&start-index=1&max-results=10&alt=json HTTP/1.1 
D/ch.boye.httpclientandroidlib.headers(2218): >> GData-Version: 2 
D/ch.boye.httpclientandroidlib.headers(2218): >> Host: picasaweb.google.com 
D/ch.boye.httpclientandroidlib.headers(2218): >> Connection: Keep-Alive 
D/ch.boye.httpclientandroidlib.headers(2218): >> Authorization: OAuth null 
D/ch.boye.httpclientandroidlib.wire(2218): << "HTTP/1.1 403 Forbidden[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): << "Expires: Fri, 17 Feb 2012 18:07:42 GMT[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): << "Date: Fri, 17 Feb 2012 18:07:42 GMT[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): << "Cache-Control: private, max-age=0, must-revalidate[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): << "Content-Type: text/plain[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): << "X-Content-Type-Options: nosniff[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): << "X-Frame-Options: SAMEORIGIN[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): << "X-XSS-Protection: 1; mode=block[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): << "Set-Cookie: S=photos_html=UJsnbriEAQZm6J0wEJjfgA; Domain=.google.com; Path=/; Secure; HttpOnly[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): << "Server: GSE[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): << "Transfer-Encoding: chunked[\r][\n]" 
D/ch.boye.httpclientandroidlib.wire(2218): << "[\r][\n]" 
D/class ch.boye.httpclientandroidlib.impl.conn.DefaultClientConnection(2218): Receiving response: HTTP/1.1 403 Forbidden 
D/ch.boye.httpclientandroidlib.headers(2218): << HTTP/1.1 403 Forbidden 
D/ch.boye.httpclientandroidlib.headers(2218): << Expires: Fri, 17 Feb 2012 18:07:42 GMT 
D/ch.boye.httpclientandroidlib.headers(2218): << Date: Fri, 17 Feb 2012 18:07:42 GMT 
D/ch.boye.httpclientandroidlib.headers(2218): << Cache-Control: private, max-age=0, must-revalidate 
D/ch.boye.httpclientandroidlib.headers(2218): << Content-Type: text/plain 
D/ch.boye.httpclientandroidlib.headers(2218): << X-Content-Type-Options: nosniff 
D/ch.boye.httpclientandroidlib.headers(2218): << X-Frame-Options: SAMEORIGIN 
D/ch.boye.httpclientandroidlib.headers(2218): << X-XSS-Protection: 1; mode=block 
D/ch.boye.httpclientandroidlib.headers(2218): << Set-Cookie: S=photos_html=UJsnbriEAQZm6J0wEJjfgA; Domain=.google.com; Path=/; Secure; HttpOnly 
D/ch.boye.httpclientandroidlib.headers(2218): << Server: GSE 
D/ch.boye.httpclientandroidlib.headers(2218): << Transfer-Encoding: chunked 
D/class ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient(2218): Connection can be kept alive indefinitely 
0
在你的IDE,比如Eclipse

,把一個斷點httpclient.execute(httppost);

然後在表達式wi ndow,添加httppost變量,以查看該值是什麼。

現在你可以擺脫所有的日誌記錄東西