@shakeelameer wrote:
Hi Everyone,
I’m having some problems sending an HTTP POST request with Angular 4 using ASMX WebService. The request arrives to the HTTP server, but apparently service finds no parameters. Here is the code:
code in config.ts
export let SERVER_URL = 'http://masjidcommunicator.com/mobileservice/WebService.asmx/';
code in Headers.ts
getXMLHeader(): Headers { let headers = new Headers(); headers.append('Content-Type','application/xml'); headers.append('Access-Control-Allow-Origin', '*'); headers.append('Access-Control-Allow-Credentials', 'true'); headers.append('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE , OPTIONS'); headers.append('Access-Control-Allow-Headers', 'Content-Type, '); return headers; }
code in Provider.ts
insertNewUser(data): Observable<any> { this.END_POINT = SERVER_URL + 'InsertNewMasjid'; console.log(JSON.stringify(data)); return this.http.post(`${this.END_POINT}`, data, { headers: this.headers.getXMLHeader() }); }
code in home.ts
user = { SchoolName: '', FirstName: '', LastName: '', SchoolPassword: '', SchoolEmail: '', SchoolAddress: '', SchoolLogo: '', SchoolPhoneNumber: '', SchoolGuid: '', AccountAcitve: '', SchoolCode: '', BusinessTypeId: '' }; constructor(public navCtrl: NavController, public navParams: NavParams, public alertCtrl: AlertController, public operations: OperationsProvider, public loader: LoaderProvider) { } addnewuser() { this.operations.insertNewUser(this.user).subscribe(res => { console.log(res); }, error => { alert(ERROR); }); }
And on submitting data i’m getting this error:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
System.InvalidOperationException: Request format is invalid: application/xml.
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()and no value is being sent to the service parameters.
So I’m not sure if I’m passing the parameters to the server the right way. It should receive the value of post parameters, named SchoolName, FirstName, LastName, SchoolPassword etc.
but it doesn’t.Thanks in advance!
Posts: 1
Participants: 1