آگاهسازیها
پاککردن همه
فرم ساز و BPMS
0
ارسال ها
1
کاربران
0
Likes
18
نمایش
0
11 تیر 1404 10:29 ق.ظ
شروع کننده موضوع
میخوام در next js با api یک فرصت فروش ایجاد کنم اما در جواب این درخواست خطا وجود داره:
این کد هست:
import axios from 'axios';
export const useSaveOpportunitySoap = () => {
const sendToCrm = async (formData) => {
const today = new Date().toISOString();
const description = Object.entries(formData)
.map(([key, value]) => `${key}: ${value}`)
.join(' | ');
console.log(description)
const xml = `<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
</s:Header>
<s:Body>
<SaveOpportunity xmlns="http://tempuri.org/">
<username>aaaaaa</username>
<password>bbbbbbbb</password>
<opportunityInfo xmlns:d4p1="http://schemas.datacontract.org/2004/07/Septa.PayamGostar.ServiceLayer.Contract.PGContracts.DataContracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<d4p1:CrmObjectTypeCode>orgsale100</d4p1:CrmObjectTypeCode>
<d4p1:IdentityId>7c66626a-9a8e-4c73-94fd-95a658dda00f</d4p1:IdentityId>
<d4p1:Subject>امکان سنجی وایرلس هرمزنت</d4p1:Subject>
<d4p1:OpportunityType>فروش وایرلس</d4p1:OpportunityType>
<d4p1:OpportunitySourceType>امکان سنجی آنلاین</d4p1:OpportunitySourceType>
<d4p1:SaleStage>فرصت فروش</d4p1:SaleStage>
<d4p1:Description>name: تست| familyName: تست | fatherName: محمد | nationalId: 1234567890 | Certificate: 1234567890 | Sex: male | birthDate: 1404/03/14 | mobile: 09123456789| landlineNumber: 02132456520 | Email: testpg@gmail.com | postalCode: 1234567890 | address: تهران خیابان ملت | city: بندرعباس | province: tehran | latitude: 35.737986 | longitude: 51.286634</d4p1:Description>
</opportunityInfo>
</SaveOpportunity>
</s:Body>
</s:Envelope>`;
try {
const response = await axios.post(
'https://aa.bbbbbbb.com/services/api/iopportunity.svc',
xml,
{
headers: {
'Content-Type': 'text/xml',
'SOAPAction': 'http://tempuri.org/IOpportunity/SaveOpportunity',
},
}
);
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(response.data, 'text/xml');
const success = xmlDoc.getElementsByTagName('Success')[0]?.textContent;
const message = xmlDoc.getElementsByTagName('Message')[0]?.textContent;
return {
success: success === 'true',
message: message || 'پاسخی دریافت نشد',
};
} catch (error) {
console.error('خطا در SOAP:', error);
return {
success: false,
message: 'خطا در ارسال درخواست به سرور',
};
}
};
return { sendToCrm };
};
این هم خطا:
Access to XMLHttpRequest at 'https://pg.hormoznet.net/services/api/iopportunity.svc' from origin 'http://localhost:3030' 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.
نتیجه درخواست:
AxiosError {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}