-1

I have tried call API From FE with API is: http://localhost/search?userName=...

get(endpoint: string, responseType = 'json', params: HttpParams = null): Observable<any> {
    let url = this.getHost() + endpoint;
    if (params?.toString()) {
      endpoint += `?${params.toString()}`;
    }
    const headers = this.getAuthHeaders(endpoint);
    const options = {
      headers: headers,
      responseType: responseType as 'json',
      params,
    };
}

And it also returns

You do not have the permission to perform this action. Error 1004 Provided nonce does not match computed nonce

When I try to send userName that has white space or a special character like ` in API And nonce in headers must match with rest framework simplify

This problem will only occur when the parameter contains spaces or strange characters like `

3 Answers 3

0

Please provide some code. How do you create the URL-string? Do you use the https://angular.dev/api/common/http/HttpParams or do you simply append the username to the URL-string (which does not work with special characters)?

You should prefer using the HttpParams, but you can use https://angular.dev/api/common/http/HttpUrlEncodingCodec as well.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your suggestion I used HttpParams but the error is still there. I have add provide some code for this question
0

Since you are directly hitting a URI you are somewhat limited in what characters may exist in any data that you send. Generally speaking, the characters that you can use are as follows -

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=

Any character that is not in this list is normally represented using an encoding in the form of %xx. For example a whitespace is represented by %20% and back-ticks "`" are represented by %60 so you would need to use such encodings to send the special characters. A list of the encodings can be found here - https://www.w3schools.com/tags/ref_urlencode.ASP

You can use the library urlib to endcode your string with this function- urllib.parse.urlencode (for python 3) and urlencode() (for python 2)

1 Comment

I think this is a problem from FE when trying to create AuthHeaders for call API,
0

Because HttpParams.toString() will encode special characters but when getNonce() in rest-framework-signature URL is not in encoded form

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.