0

Mit IBM Mobile First Platform Version 7.1 Ich versuche, einen Java-Adapter von der iOS-Anwendung mit dem folgenden Code aufzurufen.IBM MobileFirst sendet JSON-Nachrichtentext vom iOS-SDK an den Java-Adapter

[[WLResourceRequest requestWithURL:url method:WLHttpMethodPost] sendWithJSON:@{@"one":@"two"} completionHandler:^(WLResponse *response, NSError *error) { 

    NSLog(@"%@",response); 
    NSLog(@"%@",error); 

    }]; 

Java-Methode auf der Adapterseite sieht wie folgt aus.

@POST 
@Consumes("application/json") 
@Produces("application/json") 
public String hello(JSONObject body){ 
    return body.toString(); 
} 

aber ich bekomme folgende Fehlermeldung in Reaktion

2016-04-20 11: 31: 15.520 mbs-call [15092: 3787968] Fehler Domain = com.alamofire.error.serialization.response Code = -1011 "Anforderung fehlgeschlagen: nicht unterstützter Medientyp (415)" UserInfo = {com.alamofire.serialization.response.error.response = {URL: http: /0.0.0.0: 10080/mbs-api/adapter/basicadpt/Benutzer} {Statuscode: 415, Header { Verbindung = Schließen; "Inhalt-Sprache" = "en-US"; "Inhaltslänge" = 0; Date = "Mi, 20 Apr 2016 02:31:15 GMT"; "X-Powered-By" = "Servlet/3.0"; }}, NSErrorFailingURLKey = http://0.0.0.0:10080/mbs-api/adapters/basicadpt/users, com.alamofire.serialization.response.error.data = <>, NSLocalizedDescription = Request fehlgeschlagen: nicht unterstützten Medientyp (415)}

Und es scheint, dass in iOS SDK fügt Header application/x-www-url-form-urlencoded in Anfrage, wenn eine Methode aufgerufen wird.

Ich habe folgende 2 Fragen.

  1. Wie JSON Body an Java-Adapter übergeben?
  2. Das Verhalten von sendWithJSON unterscheidet sich auf iOS und Android. Auf Android scheint es application/json Header hinzuzufügen, wenn wir Adapter aufrufen. Ist das ein Fehler oder ein Teil des Verhaltens?

Antwort

1

Ich glaube, das ist ein Fehler. Ich denke, dass die Verwendung von sendWithJSON automatisch davon ausgehen sollte, dass der Inhaltstyp application/json ist.

Ich schlage vor, dass Sie eine Supportanfrage (PMR) öffnen, damit sie das Erlebnis verbessern können.

In der Zwischenzeit fand ich eine einfache Abhilfe:

[request addHeaderValue:@"application/json" forName:@"Content-Type"] 

Oder in Swift:

request.addHeaderValue("application/json", forName: "Content-Type") 
0

ich mit der cordova Version einer Anwendung das gleiche Problem hatte.

var userIDTag = 'some_string'; 
var subTag = [userIDTag]; //<- this worked 
var subTag = userIDTag; //<- this failed with the above error 
var subTag = '[\'' + some_string + '\']'; //<- this also failed with the above error 

Das unten ist, was ich für eine Cordova App getan habe.

function subscribeByTag(userIDTag) { 
    var subTag = [userIDTag]; 
    console.log("subTag: " + subTag); 
    WLAuthorizationManager.obtainAccessToken("push.mobileclient").then(
     MFPPush.subscribe(
      subTag, 
      function(subTag) { 
       navigator.notification.alert("Subscribed successfully"); 
      }, 
      function(failureResponse){ 
       navigator.notification.alert("Failed to subscribe"); 
       console.log("Failedtosubscribe:" + JSON.stringify(failureResponse)); 
      } 
     ) 
    ); 
}