I want to intercept a GET request but it doesn't work as I wanted:
// https://***.com/api/v1/receipt/suggestions?type=receipt&finance_type=purchase&is_invoice=0&cache_buster=FlYeNfBNG5ZY66
// https://***.com/api/v1/receipt/630ba8b4f7005c058a702534?cache_buster=LcsJ1esqykcp93
cy.intercept({
method: 'GET',
url: `${Cypress.env('API_URL')}/api/v1/receipt/*?cache_buster=*`,
}).as('getReceipt');
This intercept intercepts the first url, but I want to intercept the second url. Any suggestions how to make the * more strict?
Related
I'm having a problem to make a call to a rest API.
In the document (FAQ) of the web application there is an example that use AJAX request to make the call. Here an example:
var url = 'https://example.com/yyy';
$.ajax({
type: 'POST',
url: url,
cache: false,
data: {
opt: JSON.stringify(example)
},
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (result)
{
console.log(result);
} });
I created a local page with this code to made the post to the API that is located on a remote server but I receive an error about CORS.
Is there any solution to circumvent this problem? I tried to use firefox plugin to allow CORS but it didn't solve the problem. The session is authenticated via form before use the endpoint.
I see several issues:
Try to run the code from a domain and not from local disk (alternatively you can consider using https://crossorigin.me/ )
How does the authentication work? if with cookies you need to add withCredentials to the ajax request.
Make sure the API returns Access-Control-Allow-Origin: foo header where foo is the domain your code runs in. If you also used withCredentials, you should add Access-Control-Allow-Credentials: true
I am working with back end written by another developer. I think he used Web API 2.0 and Entity Framework. Specifically I am having a problem with POST. Here is the code:
public CL_CASE Post([FromBody]CL_CASE value)
{......
I am testing it using Chrome's Advanced Rest Client. I am specifying a few parameters and clicking Send. The value I am getting is null. What might be causing that?
var response = $http({
method: 'POST',
withCredentials: true,
dataType: "json",
data: JSON.stringify(payload),
params: '',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Content-Type': 'application/x-www-form-urlencoded'
},
url: url
});
payload is an object with properties that match CL_CASE.
There are a couple things you can check.
First, are the parameters you are passing in the body of the post or on the query string? The attribute [FromBody] on the value argument passed into the Post method is telling the model binder to look in the body of the HTTP request for matching parameters.
It's also important that the parameters you are passing are being specified using the correct Content-Type. Are you using a Content-Type header? If not, the expectation is probably that you are using form encoding. If that's the case, you should be specifying your parameters in the body like this:
paramName1=paramValue¶mName2=paramValue
Be sure the case of the parameter matches the case used for the matching property in the CL_CASE class too. These can be different cases and still be matched if you are using the right ContractResolver.
Another thing to be sure of is that you are in fact choosing to POST instead of GET.
Are there any other attributes on the Post method in your controller? If there are, these could be throwing off the binding.
I'm using web api without deep understanding what it is, just knowing that each editable entity become a resource, that means has the uri, when web api provides the interpretation of PUT, POST, GET, DELETE HTTP commands to support CRUD operations. But what if for tracing/logging purpose I need to send correlation token together with e.g. GET request? Are there any recommendations and techniques to add to the HTTP request/routing "technical parameters"?
I have found something that need to be tested https://webapicorrelator.codeplex.com/ But actually I would prefer just to understand how it could work...
Or just add it to the heder using jquery ajax headers:
return $.ajax({
// have to use synchronous here, else the function
// will return before the data is fetched
url: url,
data: { ElectrodeId: electrodeId },
headers: { "X-CorrelationToken": correlationToken },
method: "POST",
dataType: "json",
success: function (data) {
}
I am sending a POST AJAX request using Angularjs and its $http module to Django server. Here is an example:
$http({
method: 'POST',
url: '/url/',
data: 'test data'
}).
success(function(data, status, headers, config) {
doSomeStuffWhenSuccess();
});
The problem is what I get in Django. No matter what I send the data is always the key of QueryDict object and value of that is always an empty list.
<QueryDict: {u'test data': [u'']}>
I don't have a clue why. What am I missing?
I use almost default created Django application with default middlewares only. I created only a view and set an url in url config. Version of Django is 1.3. And I configured angular's $http module to always send a header containg csrf token to satisfy Django.
I resolved this with jQuery param function. I think it's more elegant solution.
$http({
method: 'POST',
url: '/url/',
data: $.param({test: data})
})
Now it works like I wanted.
I believe django thinks you are sending a urlencoded form, ex. key=value&key2=value2...
if you'd try:
$http({
method: 'POST',
url: '/url/',
data: 'test=data'
})
You should get
<QueryDict: {u'test': [u'data']}>
You can always obtain the data (raw body content) as follows:
request.body
Hope this is what you are looking for.
I had called the GET REST API by following code :
$.getJSON('http://myapisite.com/user/1?callback=?', function(msg){
console.log(msg);
});
But for calling DELETE REST API through jquery
what i had tried is :
$.ajax({
url: 'http://mysite.com/user/1?callback=?',
type: 'DELETE',
dataType: 'json',
data: '',
success: function(response) { console.log('PUT completed'+response); }
});.
and this api is not being called , I want to know how should i call the DELETE REST API .
Thanks
You are trying to do a cross-domain request. This means that you cannot use XMLHttpRequest (the basis of AJAX) because of the same-origin policy. You are using a workaround called JSONP, which works by inserting <script> tags into your document.
Script tags will always fetch content via GET, so you can't do a DELETE, POST, PUT or suchlike with them.
The best workaround would be to have a script on your own server that proxies the DELETE request for you.