私はwebサービスの呼び出しを行うためのiosコードを開発しており、応答がうまく与えられているという点でアプリケーションで作業しています。同じwebserviceコールがアンドロイドを呼び出そうとしています。それは私の応答を与えていない、私は私の両方のコードを投稿していない動作していない誰も私はそれを把握することができますか?上記のコードでアンドロイドコードのwebserviceの応答を取得していません
IOSコード
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",k_SERVER_BASE_ADDRESS,service_name]];
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
// 2
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
request.HTTPMethod = @"POST";
[request setValue:[NSString stringWithFormat:@"%@",k_CONTENT_TYPE] forHTTPHeaderField:@"Content-Type"];
// 3
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
[dictionary setObject:[NSString stringWithFormat:@"%@",k_USER_NAME] forKey:@"APIUserName"];
[dictionary setObject:[NSString stringWithFormat:@"%@",k_PASSWORD] forKey:@"Password"];
NSLog(@"%@",dictionary);
NSError *error = nil;
NSData *data_prm = [NSJSONSerialization dataWithJSONObject:dictionary
options:kNilOptions error:&error];
NSLog(@"%@",[[NSString alloc] initWithData:data_prm encoding:NSUTF8StringEncoding]);
if (!error) {
// 4
NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request
fromData:data_prm completionHandler:^(NSData *data,NSURLResponse *response,NSError *error) {
// Handle response here..
NSLog(@"this is data : %@",data);
Androidのコード
public class GETCONTESTANTS extends AsyncTask<Void, Void, Void> {
StringEntity se;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(StartActivity.this);
pDialog.setMessage("Loading...");
pDialog.setCancelable(false);
pDialog.show();
// stateList.clear();
}
@Override
protected Void doInBackground(Void... params) {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://www.fansplay.com/wsfptb20/FBS.svc/GetContestants");
String json = "";
try {
// 3. build jsonObject
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("APIUserName", "[email protected]");
jsonObject.accumulate("country","8GB4HE1C-EFSD-4L17-VY2D-A27OC8C52F6M");
// 4. convert JSONObject to JSON to String
json = jsonObject.toString();
// ** Alternative way to convert Person object to JSON string usin Jackson Lib
// ObjectMapper mapper = new ObjectMapper();
// json = mapper.writeValueAsString(person);
// 5. set json to StringEntity
se = new StringEntity(json);
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 6. set httpPost Entity
httpPost.setEntity(se);
// 7. Set some headers to inform server about the type of the content
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
try {
HttpResponse httpResponse = httpClient.execute(httpPost);
// 9. receive response as inputStream
inputStream = httpResponse.getEntity().getContent();
"iOSのコードは、" 正常に動作し、 "アンドロイドコード" 動作していませんさ。誰でも助けてくれますか?
デバッグ、コード役に立つとlogcat出力 –
は、あなたが任意のエラー/例外を取得している投稿してみてみては? –
正確に何がエラーになっていますか? – PriyankaChauhan