2017-10-02 5 views
1

Ich habe kürzlich RESTAssured verwendet. Ich mache einen REST-Aufruf mit der RESTAssured-Bibliothek. Ich habe einen Anhang in der Anfrage, die ich anschließe "multipart()" Methode. Für meine API sollte ich als Content-Type "application/x-abc-xyz+xml" übergeben. Als ich versuchte, dies unter Verwendung " contentType()" Methode zu setzen, bekomme ich unter Fehler. Vor dem Inhaltstyp mit "multipart /" wird jedoch dieser Fehler behoben, aber ich erhalte die REST-Antwort vom Server nicht, weil er den Inhaltstyp ohne "multipart/" Präfix erwartet. Ich brauche Hilfe bei der Lösung dieses Problems. jede Hilfe würde geschätzt werden. Vielen Dank!RESTAssured Multipart content-type

java.lang.IllegalArgumentException: Content-Type application/x-Hub-mehrt + xml nicht gilt, wenn die Multiparts verwenden, es muss mit "multipart /" beginnen. bei sun.reflect.NativeConstructorAccessorImpl.newInstance0 (native Methode) bei sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62) bei sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45) bei java.lang.reflect.Constructor.newInstance (Constructor.java:423)
bei org.codehaus.groovy.reflection.CachedConstructor.invoke (CachedConstructor.java:83) bei org.codehaus.groovy.reflection.CachedConstructor .doConstructorInvoke (CachedConstructor.java:77) um org.codehaus.groovy.runtime.call site.ConstructorSite $ ConstructorSiteNoUnwrap.callConstructor (ConstructorSite.java:84) bei org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor (CallSiteArray.java:60) bei org.codehaus.groovy.runtime.callsite. AbstractCallSite.callConstructor (AbstractCallSite.java:235) bei org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor (AbstractCallSite.java:247) bei io.restassured.internal.RequestSpecificationImpl.registerRestAssuredEncoders

Antwort

1

es kann funktionieren, Sie können dies versuchen, zB: Attachment-Dateityp als ". png "

Response response = given() 
            .multiPart(new MultiPartSpecBuilder(resourceFile).fileName(filename) 
                        // controlName is the name of the 
                        // RequestParam associated with the 
                        // MultipartFile[] array 
                        .controlName("file") 
                        .mimeType("image/png") 
                        .build()) 
            .param("documentType", "MyCat") // You can omit this if U want 
            .when() 
            .post("my URI") 
            .then() 
            .extract() 
            .response(); 
+0

Vielen Dank für Ihre Antwort. Ich habe das versucht. Sie übergeben keinen Inhaltstyp in Ihrem Code, so dass "multipart/form-data" als Standardinhaltstyp verwendet wird. In meinem Fall versuche ich "application/x-abc-xyz + xml" als Inhaltstyp zu übergeben. – kav12345

Verwandte Themen