Code:
<System.Web.Services.WebMethod()>
Public Shared Async Function TestAjaxCall(ByVal url As String) As Threading.Tasks.Task(Of Boolean)
Using client = New HttpClient()
client.BaseAddress = New Uri(url)
client.DefaultRequestHeaders.Accept.Clear()
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))
Dim response As HttpResponseMessage = Await client.GetAsync("/api/v1/accounts")
If response.IsSuccessStatusCode Then
Return True
Else
Return False
End If
End Using
End Function
I am calling the code like so
Code:
fetch('http://localhost:27578/organisation/manage/manage.aspx/TestAjaxCall', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ url: 'https://test.instructure.com' }),
})
.then(response => response.json())
.then(parsedJson => console.log(parsedJson.d))
.catch(err => setCheckConnection(false));
}, []);