0

Spent hours trying to figure this one out. Response Message always has a 404 Not found error. Any help will be greatly appreciated!

public static class BackendlessAPIHelper
{
    internal static string appId = "my-app-id";
    internal static string restSecret = "my-api-secret";
    internal static string backendlessBase = "https://api.backendless.com/";
    internal static string signupUrl = "v1/user/register";

    public static async Task<bool> UserSignup(string username, string password)
    {
        bool signupsuccessful = false;
        var client = new HttpClient();
        UserSignupBackendless newuser = new UserSignupBackendless { email = username, password = password };
        string newuserjson = JsonConvert.SerializeObject(newuser);

        try
        {
            client.BaseAddress = new Uri(backendlessBase);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Add("application-id", BackendlessAPIHelper.appId);
            client.DefaultRequestHeaders.Add("secret-key", BackendlessAPIHelper.restSecret);
            client.DefaultRequestHeaders.Add("application-type", "REST");
            StringContent theContent = new StringContent(newuserjson, System.Text.Encoding.UTF8, "application/json");

            HttpResponseMessage response = await client.PostAsync(backendlessBase+signupUrl, theContent);
            if (response.IsSuccessStatusCode)
            {
                signupsuccessful = true;
                return signupsuccessful;
            }
            else
                return signupsuccessful;
        }
        catch(Exception ex)
        {
            ex.ToString();
            return signupsuccessful;
        }
    }
}

Here's the API documentation: https://backendless.com/documentation/users/rest/users_user_registration.htm

I followed the article located here: http://blogs.msdn.com/b/wsdevsol/archive/2013/02/05/how-to-use-httpclient-to-post-json-data.aspx

Update: I realized the mistake. The signup URL was incorrect (missed a character).

2
  • You may want to check out Fiddler, takes the guess-work out of debugging stuff like this. Commented Mar 5, 2016 at 1:41
  • Thanks @Aydin Adn. I'll definitely give that a try. Commented Mar 5, 2016 at 4:24

1 Answer 1

4

I think your base URL is getting duplicated:

client.BaseAddress = new Uri(backendlessBase);
// ...
HttpResponseMessage response = await client.PostAsync(backendlessBase+signupUrl, theContent);

You're specifying backendlessBase twice. If you already specified the base using BaseAddress, don't specify it again in the call.

Also if you read the docs carefully, it's users/register, not user/register.

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

2 Comments

I removed backendlessBase from the PostAsync call. it now has the signupUrl. Still returns the same error.
yep, I realized that just now. Thanks for pointing it out, @Matti Virkkunen.

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.