teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

5

ミスタイプ

2017/03/03 09:04

投稿

SmartBuzz
SmartBuzz

スコア81

title CHANGED
File without changes
body CHANGED
@@ -58,7 +58,7 @@
58
58
  // コンテンツの長さを取得
59
59
  try {
60
60
  // StringBuilderを文字列に変化してからバイト長を取得
61
- length = strings[0].getBytes(CHARSET).length;
61
+ length = strings[1].getBytes(CHARSET).length;
62
62
  } catch (UnsupportedEncodingException e1) {
63
63
  e1.printStackTrace();
64
64
  }

4

解決済みコードに編集

2017/03/03 09:04

投稿

SmartBuzz
SmartBuzz

スコア81

title CHANGED
File without changes
body CHANGED
@@ -26,7 +26,7 @@
26
26
  (2は通信エラー系です)
27
27
 
28
28
 
29
-
29
+ ※コードを解決済みコードに編集しました
30
30
  ```java
31
31
 
32
32
  // 挿入用データをString型で作成
@@ -48,18 +48,36 @@
48
48
  protected Void doInBackground(String... strings) {
49
49
 
50
50
  URL url = null;
51
+ int length = 0;
51
52
  try{
52
53
  url = new URL(strings[0]);
53
54
  }catch(MalformedURLException e){
54
55
  e.printStackTrace();
55
56
  }
56
57
 
57
- HttpURLConnection con = null;
58
+ // コンテンツの長さを取得
58
59
  try {
60
+ // StringBuilderを文字列に変化してからバイト長を取得
61
+ length = strings[0].getBytes(CHARSET).length;
62
+ } catch (UnsupportedEncodingException e1) {
63
+ e1.printStackTrace();
64
+ }
65
+
66
+ Log.d("XML",strings[1]);
67
+
68
+ HttpsURLConnection con = null;
69
+ try {
59
- con = (HttpURLConnection) url.openConnection();
70
+ con = (HttpsURLConnection) url.openConnection();
71
+ con.setRequestMethod("POST");
60
72
  con.setDoOutput(true);
61
73
  con.setDoInput(true);
62
- con.setChunkedStreamingMode(0);
74
+ con.setFixedLengthStreamingMode(245);
75
+ // 持続接続を設定
76
+ con.setRequestProperty("Connection", "Keep-Alive");
77
+ // POSTデータの形式を設定
78
+ con.setRequestProperty("Content-Type", String.format("text/plain; boundary=%s", BOURDARY));
79
+ // POSTデータの長さを設定
80
+ con.setRequestProperty("Content-Length", String.valueOf(length));
63
81
  con.connect();
64
82
 
65
83
  // POSTデータ送信処理
@@ -92,6 +110,8 @@
92
110
  buffer.append(temp);
93
111
  }
94
112
 
113
+ Log.d("BUFF",buffer.toString());
114
+
95
115
  }
96
116
 
97
117
  } catch (IOException e) {

3

リクエストとレスポンスの状況追加

2017/03/03 08:52

投稿

SmartBuzz
SmartBuzz

スコア81

title CHANGED
File without changes
body CHANGED
@@ -124,4 +124,16 @@
124
124
  |P03_01|test|ELM|/test/|||
125
125
  |P03_02|name|TXT|/test/name|CHAR|送信内容|
126
126
  |P03_03|address|TXT|/test/address|VACHAR|送信内容|
127
- |P03_04|code|TXT|/test/address|CHAR|1:完了2:通信エラー系など3:重複登録4:その他エラー|
127
+ |P03_04|code|TXT|/test/address|CHAR|1:完了2:通信エラー系など3:重複登録4:その他エラー|
128
+
129
+
130
+ 【サーバーへのリクエスト】
131
+ dataStringをログで出したもの
132
+ > コード
133
+ > <test><address>test@test.co.jp</address><name>testname</name></test>
134
+
135
+
136
+ 【サーバーからのレスポンス】
137
+ bufferをwhileが終わった後に.toStringしてログで出したもの
138
+ > コード
139
+ <?xml version="1.0" encoding="Shift_JIS"?><test> <name></name><address></address> <code>2</code></test>

2

サーバー側の仕様を追加

2017/03/02 01:36

投稿

SmartBuzz
SmartBuzz

スコア81

title CHANGED
File without changes
body CHANGED
@@ -107,4 +107,21 @@
107
107
  }
108
108
  ```
109
109
 
110
- よろしくお願いします。
110
+ よろしくお願いします。
111
+
112
+ 【サーバー側仕様】
113
+ 「アプリ⇨サーバー」
114
+ |データID|データ名称|分類|Xpath式|データ型|
115
+ |:--|:--:|--:|
116
+ |P01_01|test|ELM|/test/||
117
+ |P01_02|name|TXT|/test/name|CHAR|
118
+ |P01_03|address|TXT|/test/address|VACHAR|
119
+
120
+ 「サーバー⇨アプリ」
121
+ 上記の要求に対する応答
122
+ |データID|データ名称|分類|Xpath式|データ型|応答内容|
123
+ |:--|:--:|--:|
124
+ |P03_01|test|ELM|/test/|||
125
+ |P03_02|name|TXT|/test/name|CHAR|送信内容|
126
+ |P03_03|address|TXT|/test/address|VACHAR|送信内容|
127
+ |P03_04|code|TXT|/test/address|CHAR|1:完了2:通信エラー系など3:重複登録4:その他エラー|

1

うまく行っていないところの情報追加

2017/03/02 01:28

投稿

SmartBuzz
SmartBuzz

スコア81

title CHANGED
File without changes
body CHANGED
@@ -3,12 +3,30 @@
3
3
  送りたい形式は
4
4
  <test>
5
5
  <name>name</name>
6
- <adress>adress</adress>
6
+ <address>address</address>
7
7
  </test>
8
8
  という形式を送りたいです。
9
9
 
10
- 現状、サーバーからレスポンス返ってきていますが、うまく上記のデータが送れていないようです。
10
+ 現状、サーバーからレスポンス返ってきますが、うまく内容が送れていないようです。
11
+ サーバーからのレスポンスは、今回送った内容と登録が正常に終わったかどうかのコードが返ってきますが、現状内容が空で、通信系エラーコードが返ってきます。
11
12
 
13
+ 【期待値】
14
+ <test>
15
+ <name>teratail</name>
16
+ <address>test@teratail.com</address>
17
+ <code>1</code>
18
+ </test>
19
+
20
+ 【現状】
21
+ <test>
22
+ <name></name>
23
+ <address></address>
24
+ <code>2</code>
25
+ </test>
26
+ (2は通信エラー系です)
27
+
28
+
29
+
12
30
  ```java
13
31
 
14
32
  // 挿入用データをString型で作成