-1

I am using jQuery Ajax to make a GET request. Sometimes It works perfectly, but other times I get a 403 forbidden when I look at the chrome dev tools console. Is this a server issue or my code?

When I sign in, I get the encrypted password, username and ID back from the server. I then store that in LocalStorage since the request I am trying to get working is on another page. I am also required to make a client token from those fields using AES encryption. For that, I am using CryptoJS. For my request, I am required to send in the password, username, ID and client token that has been retrieved from LocalStorage. I realize that may not be a good way to go about it, but I do not have control of the server side.

Edit: Here is my Ajax call to the service:

 $("#system-form").submit(function (e) {
    $.ajax({
        type: "GET",
        url: "myurl",
        data: "User.Username=" + localStorage.getItem("guid") + "&User.Password=" + localStorage.getItem("password") + "&User.SecUser=" + localStorage.getItem("secUser") + "&ClientAppID=" + localStorage.getItem("ClientAppId") +"&"+ $(this).serialize(),
    })
    .done(function(data) {
        //parse data
    })
    .fail(function (xhr, textStatus, error) {
        console.log(JSON.stringify(xhr.responseText));
    });
    e.preventDefault(); 
});
ecain
  • 1,282
  • 5
  • 23
  • 54
  • 1
    possibly a duplicate of [jQuery AJAX call results in error status 403](https://stackoverflow.com/questions/36666256/jquery-ajax-call-results-in-error-status-403) – taha Jul 03 '17 at 22:39
  • 2
    `Is this a serve issue or my code?` - yes, probably one of those two – Jaromanda X Jul 03 '17 at 22:44
  • I have added the code for my `ajax` call. – ecain Jul 05 '17 at 18:36
  • I looked at the link taha posted, and I'm not sure how I would use headers. I don't have an api key. – ecain Jul 05 '17 at 18:38
  • the server is rejecting your auth parameters. there's not much we can do to help you with that. – Kevin B Jul 05 '17 at 18:39
  • I'm using the same user when testing. Do you know why the server sometimes accept the parameters, and sometimes it doesn't? – ecain Jul 05 '17 at 18:42

1 Answers1

0

I realized my issue was that I need to URL encode my auth parameters. I fixed this by using encodeURIComponent.

ecain
  • 1,282
  • 5
  • 23
  • 54