アンドロイド携帯からサーバーに情報を送信しようとしています。Android用Http Post:サーバのリクエストと応答
サーバーが情報を受け取ると、1または0が返され、合格を示すか失敗したかが返されます。サーバーサイドのすべては、同じことをするiOS用の別のアプリがあるためうまくいきますが、機能します。また、サーバーはリクエストを受信するたびに電子メールを送信します。
私の問題は、アプリケーションがサーバーに接続しているようには見えないということです。私は、アプリケーションを実行すると、応答は返されず、Http Postコードが実行されると電子メールは送信されません。
私は以下のHttp Postコードを持っています。何か助けていただきありがとうございます。
public void send()
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(site);
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("dateOfEventStart", startYear + "-" + startMonth + "-" + startDay));
nameValuePairs.add(new BasicNameValuePair("dateOfEventEnd", endYear + "-" + endMonth + "-" + endDay));
nameValuePairs.add(new BasicNameValuePair("locationType", locType));
nameValuePairs.add(new BasicNameValuePair("locationZipCode", location));
nameValuePairs.add(new BasicNameValuePair("eventType", type));
nameValuePairs.add(new BasicNameValuePair("groundSurface", groundType));
nameValuePairs.add(new BasicNameValuePair("numberOfGuests", numGuests + ""));
nameValuePairs.add(new BasicNameValuePair("seatingArrangments", arrangement));
nameValuePairs.add(new BasicNameValuePair("accessoriesTables",stuff));
nameValuePairs.add(new BasicNameValuePair("estimatedArea", tent));
nameValuePairs.add(new BasicNameValuePair("estimatedRoomToSpare", spared));
nameValuePairs.add(new BasicNameValuePair("contactName", nameA));
nameValuePairs.add(new BasicNameValuePair("contactPhone", phoneA));
nameValuePairs.add(new BasicNameValuePair("contactEmail", addressA));
nameValuePairs.add(new BasicNameValuePair("contactComments", comment));
nameValuePairs.add(new BasicNameValuePair("isInternational", isInternational + ""));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
responseString = response.toString();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
以前に宣言されたサイトは可変です。それは私はあなたがそれを(ほとんどの場合)と「POST」リクエストを送信するサーバー
について与えられた情報「のContentは、以下のフォームの受信機
の場所を含む文字列です"application/x-www-form-urlencoded"の "type"と入力します。
"POST"の内容は、WebサイトURLの "Query> String"のようにフォーマットされた文字列になります。
この文字列には、等号で接続されたキーと値があります。キーと値のペアは、アンパサンドで区切られます(& ')。ここ
は、私はそれが(読みやすくするために追加>キャリッジリターンで)に役立つ場合、サービスをテストするためにASPに使用される文字列の例である:
strContent =「dateOfEventStart = 2011-09-24
& dateOfEventEnd = 2011-09-26
& locationType = "& Server.URLEncode( "住宅")&"
& locationZipCode = 38016
& EventTypeが "& Server.URLEncode( "企業イベント")& "
& eventTypeSecondary =
& groundSurface =" & Server.URLEncode(" 汚れ上砂利() ")&"
& groundSurfaceSecondary =
& numberOfGuests = 90
& seatingArrangements =」&サーバー。URLENCODE( "6名のラウンドテーブル")& "
& accessoriesTables =" & Server.URLEncode( "ビュッフェ、ケーキ、ギフト、飲料駅")&」
& accessoriesEntertainment =
& estimatedArea = "& Server.URLEncode(" 1200平方フィート ")&"
& estimatedTentSize = "& Server.URLEncode( "30フィート×40フィートまたは20フィート×60フィート")& "
& estimatedRoomToSpare =" & Server.URLEncode( "0平方フィート又は0平方フィート")&」
& CONTACTNAME = "& Server.URLEncode( "ジョナサン・チャン")&"
& contactPhone = 9011234567
&はCONTACTEMAIL =」& Server.URLEncode( "[email protected]")& "
& contactComments =" & Server.URLEncode( "これは長いコメントです。")
私のASPの例では、文字列を囲む "Server.URLEncode"に気づいているかもしれません。これは>ですので、データを混乱させる可能性のある特定の文字は%16進ASCII>値にエンコードされます。たとえば、誰かが「私はチーズが好きです」とコメントした場合、プログラムはアンパサンドが新しいキー/値ペアを表していると考えます。 URLをエンコードすると、 "I%20love%20cheese%20%26%20cake"のようになります。
[OK]を私は権限をチェックし、インターネットのアクセス権がありませんでしたし、私が追加しました。これでサーバーと通信しますが、フォームはまだ動作していません。それは文字列を受け取るが、それを処理していないようだ – Zaask