TLaperre
New Coder
I have a endpoind that works. Get and post work from Postman. When using the postman proxy, it tells me, success and indeed, the expecterd resuls are seen there. Trying to get the results back in VScode, I have been looking for 3days sync/async nothing is working beside a status=4. A bit of help is welcome.
ex1: Works in postman:
Post: http://davincironse.com:3000/Sms
Body:
{
"mySms": {},
"smsType": 0,
"mobileNumbers": "0479123456",
"message": "testing104",
"method": 0,
"interface": 1,
"priority": 0,
"quantity": "string"
}
ex2: Works in postman:
Post: http://davincironse.com:3000/WeatherForecast
Body:
For ex1 call javasript not working:
export async function sendSmsMessage3() {
var enpointurl = "http://davincironse.com:3000/Sms";
var messageSmsDetails =
{
mySms: {},
smsType: 0,
mobileNumbers: '0479536456',
message: 'testing104',
method: 0,
interface: 1,
priority: 0,
quantity: 'string'
};
var strBody = JSON.stringify(messageSmsDetails);
var url = "http://www.davincironse.com:3000/Sms";
// url = "http://127.0.0.1:5112/Sms";
console.log(document.referrer);
try {
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-type': 'application/json; charset=UTF-8' },
body: strBody // JSON.stringify(messageSmsDetails)'
});
if (!response.ok) {
throw new Error(
}
const data = await response.json();
console.log(data);
} catch (error) {
console.error('Error:', error);
throw error;
}
};
For ex2 call javascript not working:
export async function sendSmsMessage8() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "http://davincironse.com:3000/WeatherForecast", true);
xhr.onload = (e) => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText);
} else {
console.error(xhr.statusText);
}
}
};
xhr.onerror = (e) => {
console.error(xhr.statusText);
};
xhr.send(null);
};
ex1: Works in postman:
Post: http://davincironse.com:3000/Sms
Body:
{
"mySms": {},
"smsType": 0,
"mobileNumbers": "0479123456",
"message": "testing104",
"method": 0,
"interface": 1,
"priority": 0,
"quantity": "string"
}
ex2: Works in postman:
Post: http://davincironse.com:3000/WeatherForecast
Body:
For ex1 call javasript not working:
export async function sendSmsMessage3() {
var enpointurl = "http://davincironse.com:3000/Sms";
var messageSmsDetails =
{
mySms: {},
smsType: 0,
mobileNumbers: '0479536456',
message: 'testing104',
method: 0,
interface: 1,
priority: 0,
quantity: 'string'
};
var strBody = JSON.stringify(messageSmsDetails);
var url = "http://www.davincironse.com:3000/Sms";
// url = "http://127.0.0.1:5112/Sms";
console.log(document.referrer);
try {
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-type': 'application/json; charset=UTF-8' },
body: strBody // JSON.stringify(messageSmsDetails)'
});
if (!response.ok) {
throw new Error(
HTTP error! status: ${response.status});}
const data = await response.json();
console.log(data);
} catch (error) {
console.error('Error:', error);
throw error;
}
};
For ex2 call javascript not working:
export async function sendSmsMessage8() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "http://davincironse.com:3000/WeatherForecast", true);
xhr.onload = (e) => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText);
} else {
console.error(xhr.statusText);
}
}
};
xhr.onerror = (e) => {
console.error(xhr.statusText);
};
xhr.send(null);
};