Coder Social home page Coder Social logo

Comments (11)

MatthieuNarcisi avatar MatthieuNarcisi commented on June 28, 2024 4

+1 for this too. We need to be able to send raw XML to our server (old API) and do need the requests to NOT be serialized. Sent as raw.

from cordova-plugin-advanced-http.

ilgizarg avatar ilgizarg commented on June 28, 2024 2

This method is wrong, but work
I use this.http.setDataSerializer('json');

let headers = {
       "Content-type": 'text/xml;charset="utf-8"',
       "Accept": "text/xml",
       };
let xml = 'Xml content as string';
this.http.post(soapUrl, xml, headers).then( .... ).catch(...)

For iOS
I am edit AFURLRequestSerialization.m file
/plugins/cordova-plugin-advanced-http/src/ios/AFNetworking
/node_modules/cordova-plugin-advanced-http/src/ios/AFNetworking

if (parameters) {
        if (![mutableRequest valueForHTTPHeaderField:@"Content-Type"]) {
            [mutableRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        }
        //Comment this row
        //[mutableRequest setHTTPBody:[NSJSONSerialization dataWithJSONObject:parameters options:self.writingOptions error:error]];
       //Add this row
        [mutableRequest setHTTPBody: [parameters dataUsingEncoding:NSUTF8StringEncoding]];
    }

from cordova-plugin-advanced-http.

leongzw avatar leongzw commented on June 28, 2024 1
  • 1 for this, due to the new introduced ' cordova-plugin-ionic-webview ', it enforces CORS which the previous plugin doesn't, and we couldn't able to configure at api side, we couldn't use http from angular to call soap api anymore

from cordova-plugin-advanced-http.

ilgizarg avatar ilgizarg commented on June 28, 2024 1

I'm solved (maybe is wrong method)
With this.http.setDataSerializer('json');

let headers = {
       "Content-type": 'text/xml;charset="utf-8"',
       "Accept": "text/xml",
       "Pragma": "no-cache",
       "SOAPAction": http://*.com/ws/card/getCard,
       };

let xml = '<?xml version="1.0" encoding="UTF-8"?>' +
      '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '+
      'xmlns:ns1="'+_namespace_+'"'+
      ' xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="'+_namespace_+'">'+
      '<SOAP-ENV:Header><ns2:UserCredentials>'+
      '<xsd:string>'+_username_+'</xsd:string>'+
      '<xsd:string>'+_password_+'</xsd:string>'+
      '</ns2:UserCredentials></SOAP-ENV:Header>' +
      '<SOAP-ENV:Body><ns1:'+_service_+'>'+_paramsxml_+
      '</ns1:'+_service_+'>' +
      '</SOAP-ENV:Body></SOAP-ENV:Envelope>

this.http.setDataSerializer('json');

this.http.post(soapurl, xml , headers).then( .... ).catch(...)

from cordova-plugin-advanced-http.

corran2go avatar corran2go commented on June 28, 2024

Don't know why, but this.http.setDataSerializer('json'); allows sending XML but uses 'content-type': 'application/json; charset=UTF-8', and it can't be overridden by a custom header 'Content-Type': 'application/xml; charset=utf-8'

from cordova-plugin-advanced-http.

jondediego avatar jondediego commented on June 28, 2024

Same issue here. Which version of the plugin are you using @iligzar? Your solution doesn't work for me on Android, I get an error with status 415, trying to make a call like you do. I am using plugin version 1.9.1 and ionic native version 4.5.2

http.setDataSerializer('json'); //bodyRequest is a string that contains xml http.post(url ,bodyRequest, {"SOAPAction": soapaction, "Pragma": "no-cache","Content-Type": "text/xml; charset=utf-8", "Accept": "text/xml"}).then((response) => { SOAPClient._onSendSoapRequest(isBrowser, method, async, callback, wsdl, xmlHttp); }).catch(e => { })

from cordova-plugin-advanced-http.

Steve720zhang avatar Steve720zhang commented on June 28, 2024

@jondediego
u shouldnt set 'http.setDataSerializer('json')' and '"Content-Type": "text/xml; charset=utf-8"' at the same time . its doesnt make sense.

from cordova-plugin-advanced-http.

jondediego avatar jondediego commented on June 28, 2024

Ok @Steve720zhang, so is there currently a way to send raw XML to a server with a NOT serialized body request?

from cordova-plugin-advanced-http.

silkimen avatar silkimen commented on June 28, 2024

Hi guys,

upcoming version 1.10.0 will support a new serializer utf8, which should solve your problem.

e.g. without ionic-native wrapper:

http.setDataSerializer('utf8');
http.setHeader('text/xml; charset=utf-8');

http.post(url, xmlString, additionalHeaders, successHandler, failHandler);

e.g. with ionic-native wrapper:

this.http.setDataSerializer('utf8');
this.http.setHeader('text/xml; charset=utf-8');

this.http.post(url, xmlString, additionalHeaders)
  .then(...)
  .catch(...)

Basically this "serializer" is just a feature which is passing your string as plain text to the server. So I could have called it plain, text or none, but I've decided to call it utf8, because it only supports this encoding.

Please check if this feature fits your needs!

from cordova-plugin-advanced-http.

mgmanoj avatar mgmanoj commented on June 28, 2024

this.http.setHeader('text/xml; charset=utf-8');
Typescript highlight the above code as error 'Expected 2 arguments, but got one'

from cordova-plugin-advanced-http.

glen442 avatar glen442 commented on June 28, 2024

The documentation says:

setHeader(host, header, value)

Set a header for all future requests. Takes a hostname, a header and a value.

Param Type Details
host string The hostname to be used for scoping this header
header string The name of the header
value string The value of the header

from cordova-plugin-advanced-http.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.