MobileFirst adapter invocation failed with -unsupported media type error

点点圈 提交于 2019-12-12 10:23:24

问题


We have mobilefirst adapter its working properly in swagger tool but when we are trying to invoke from client side its giving error for unsupported media type-errorcode 415.Environment mobilefirst 8.0 with ibm cloud object storage .

server side java adapter code below like that,
    -----------------------------------------
    @POST
    @Path("/uploadImageToObjectStorage")
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @OAuthSecurity(enabled = false)
    public String uploadImage(@QueryParam(value="imageName") String imageNameWithExtn, @QueryParam(value="imageMimeType") String imageMimeType, @FormParam(value="imageDataInBase64Str") String imageBase64String){

    /// do to


    }

    cordova ionic 2 calling adapter or invoke adapter like that,
    -------------------------------------------------------------
    var resourceRequest = new WLResourceRequest("/adapters/Test/TestAdp/upload",WLResourceRequest.POST);
     resourceRequest.send().then((response) => {
        resourceRequest.setQueryParameter("imageName", 'store');
        resourceRequest.setQueryParameter("imageMimeType",'image/png'); 
        resourceRequest.setQueryParameter("imageDataInBase64Str",this.imageDataInBase64Str);  
        },
    function(error){
        console.log(error);
    });

{"status":415,"statusText":"Unsupported Media Type","responseText":"","responseHeaders":{"connection":"Keep-Alive","content-language":"en-US","date":"Tue, 21 Nov 2017 14:09:31 GMT","transfer-encoding":"chunked","x-backside-transport":"FAIL FAIL","x-global-transaction-id":"4266505935","x-powered-by":"Servlet/3.1"},"errorMsg":"Unsupported Media Type","errorCode":"415"}


回答1:


You should set the Content-Type of your resourceRequest to application/ x-www-form-urlencoded.




回答2:


Add this line in your code

resourceRequest.setHeader('Content-Type','application/x-www-form urlencoded');




回答3:


I was implementing the device token adapter using IBM Work light and i got same error :

unsupported media (45) type error

when i used this :

request?.setHeaderValue("application/json" as NSObject, forName: "Content-Type") 

Resolved my issue , try this.



来源:https://stackoverflow.com/questions/47415586/mobilefirst-adapter-invocation-failed-with-unsupported-media-type-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!