# HttpClient Example Issues

**URL:** <https://community.particle.io/t/httpclient-example-issues/13086>\
**Category:** Getting Started\
**Created:** [July 8, 2015, 4:37pm UTC](https://community.particle.io/t/httpclient-example-issues/13086 "2015-07-08T16:37:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@Leon](https://community.particle.io/u/Leon)\
**Post date:** [July 8, 2015, 4:37pm UTC](https://community.particle.io/t/httpclient-example-issues/13086/1 "2015-07-08T16:37:26Z")

</div>

I am trying to get the HttpClient example working with the [www.timeapi.org](http://www.timeapi.org) website to tell me the time, but I only keep getting this response from the serial port.

[![](http://puu.sh/iRJdg/f8ca251a9a.png) ](http://puu.sh/iRJdg/f8ca251a9a.png)

This is the code I am using.

```auto
#include "application.h"
#include "HttpClient/HttpClient.h"

/**
* Declaring the variables.
*/
unsigned int nextTime = 0; // Next time to contact the server
HttpClient http;

// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
    // { "Content-Type", "application/json" },
    // { "Accept" , "application/json" },
    { "Accept" , "*/*"},
    { NULL, NULL } // NOTE: Always terminate headers will NULL
};

http_request_t request;
http_response_t response;

void setup() {
    Serial.begin(9600);
}

void loop() {
    if (nextTime > millis()) {
        return;
    }

    Serial.println();
    Serial.println("Application>\tStart of Loop.");
    // Request path and body can be set at runtime or at setup.
    request.hostname = "www.timeapi.org";
    request.port = 80;
    request.path = "/utc/now";

    // The library also supports sending a body with your request:
    //request.body = "{\"key\":\"value\"}";

    // Get request
    http.get(request, response, headers);
    Serial.print("Application>\tResponse status: ");
    Serial.println(response.status);

    Serial.print("Application>\tHTTP Response Body: ");
    Serial.println(response.body);

    nextTime = millis() + 10000;
}

```

Can anyone help me out?

* * *

_I’ve edited your post to properly format the code. Please check out [this post](https://community.particle.io/t/forum-tips-and-tricks/3999/2), so you know how to do this yourself in the future. Thanks in advance! ~Jordy_

---

<div class="post-metadata">

**Author:** ![secondshutter](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/secondshutter/32/5879_2.png) [@secondshutter](https://community.particle.io/u/secondshutter)\
**Post date:** [July 11, 2015, 9:14pm UTC](https://community.particle.io/t/httpclient-example-issues/13086/2 "2015-07-11T21:14:48Z")

</div>

I am having the same issue.

---

<div class="post-metadata">

**Author:** ![Leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@Leon](https://community.particle.io/u/Leon)\
**Post date:** [July 13, 2015, 3:43pm UTC](https://community.particle.io/t/httpclient-example-issues/13086/3 "2015-07-13T15:43:44Z")

</div>

I tried another website and it ended up working, so try to find another website and see if that solves your issue.

---

<div class="post-metadata">

**Author:** ![dougal](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dougal/32/20713_2.png) [@dougal](https://community.particle.io/u/dougal)\
**Post date:** [July 13, 2015, 9:22pm UTC](https://community.particle.io/t/httpclient-example-issues/13086/4 "2015-07-13T21:22:01Z")

</div>

I just did some experimenting, and determined that this site (for whatever reason) will only accept a request that includes a “User-agent” header in the request. Try adding that in your code, and it should work.

```
http_header_t headers[] = {
    // { "Content-Type", "application/json" },
    // { "Accept" , "application/json" },
    { "Accept" , "*/*"},
    { "User-agent", "Particle HttpClient"},
    { NULL, NULL } // NOTE: Always terminate headers will NULL
};
```

---

<div class="post-metadata">

**Author:** ![secondshutter](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/secondshutter/32/5879_2.png) [@secondshutter](https://community.particle.io/u/secondshutter)\
**Post date:** [July 14, 2015, 5:28pm UTC](https://community.particle.io/t/httpclient-example-issues/13086/5 "2015-07-14T17:28:49Z")

</div>

Awesome! Thanks.
