I’ve a problem when I try to send an XML object to Geoserver.
When I try with Postman it sends successfully, even in Geoserver Demo.
But with my emulator I get these errors.
I’ve tried HTTPClient, XMLHttpRequest and HTTP from '@ionic-native/http/ngx';
but I don’t get a good feedback.
With XMLHttpRequest and HttpClient I get this error:
Access to XMLHttpRequest at ‘http://ip_address:port/geoserver/worksapce/wfs’ from origin ‘http://localhost’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
And with HTTP from '@ionic-native/http/ngx';
I get this one
Error: advanced-http: “data” option is configured to support only following data types: Object
at Object.processData (helpers.js:400)
at Object.sendRequest (public-interface.js:158)
at Object.post (public-interface.js:174)
at callCordovaPlugin (vendor-es2015.js:98821)
at vendor-es2015.js:98636
at vendor-es2015.js:98594
at new ZoneAwarePromise (polyfills-es2015.js:3882)
at tryNativePromise (vendor-es2015.js:98593)
at getPromise (vendor-es2015.js:98614)
at wrapPromise (vendor-es2015.js:98619)
Here is my code
var xmlData= '<wfs:Transaction service="WFS" version="1.0.0" '+
'xmlns:topp="http://www.openplans.org/topp" '+
'xmlns:ogc="http://www.opengis.net/ogc" '+
'xmlns:wfs="http://www.opengis.net/wfs">'+
'<wfs:Update typeName="topp:tasmania_roads">'+
'<wfs:Property>'+
'<wfs:Name>TYPE</wfs:Name>'+
'<wfs:Value>street</wfs:Value>'+
'</wfs:Property>'+
'<ogc:Filter>'+
'<ogc:FeatureId fid="tasmania_roads.1"/>'+
'</ogc:Filter>'+
'</wfs:Update>'+
'</wfs:Transaction>';
//Request using HttpCLient
let doc = parser.parseFromString(xmlData, "application/xml");
let headers = new HttpHeaders()
.set("Authorization", btoa("admin:geoserver"))
.set('Access-Control-Allow-Origin', '*')
.set('Content-Type', 'application/xml');
this.httpClient.post(this.ENDPOINT + 'geoserver/workspace/wfs', doc, {headers: headers,
withCredentials : true, observe : 'body'})
.subscribe((rs) => {
console.error(rs);
})
//Request using HTTP
this.httpNative.post(this.ENDPOINT + 'geoserver/firca_demo/wfs',xmlData , {
Authorization: btoa("admin:geoserver"), 'Content-Type': 'application/xml',
}
).then((rs) => {
console.log(rs);
}).catch((err) => {
console.error(err);
})
Need help to solve it.