# HTTP Request issue

**URL:** <https://community.particle.io/t/http-request-issue/2436>\
**Category:** Troubleshooting\
**Created:** [January 28, 2014, 9:05pm UTC](https://community.particle.io/t/http-request-issue/2436 "2014-01-28T21:05:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeroen3](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@Jeroen3](https://community.particle.io/u/Jeroen3)\
**Post date:** [January 28, 2014, 9:05pm UTC](https://community.particle.io/t/http-request-issue/2436/1 "2014-01-28T21:05:39Z")

</div>

Somehow I cannot get a HTTP Request complete.

I’m running a state machine in loop, a state transition requires the loop to restart with a 1 ms delay.  
State 1: Connect to [192.168.1.100](http://jeroen3.nl/rheden/)\*:80 (success)  
State 2: Send HTTP Request (success)  
State 3: Receive webpage (failure)  
Responce should be, according to pc terminal`HTTP/1.1 200 OK<\r><\n>
Date: Tue, 28 Jan 2014 20:31:10 GMT<\r><\n>
Server: Apache<\r><\n>
Vary: Accept-Encoding<\r><\n>
Content-Length: 11<\r><\n>
Connection: close<\r><\n>
Content-Type: text/html<\r><\n>
<\r><\n>
< 1234;12 ><\r><\n>`  
Resonse Spark Core reads is:

`
HTTP/1.1 200 OK<\r><\n>
Date: Tue, 28 Jan 2014 20:34:24 GMT<\r><\n>
Server: Apache<\r><\n>
Vary: Accept-En`  
It just ends after about 80-100 chars, my code keeps reading, but nothing is coming.

Strange part is, the google example does work, but only occasionally.

[Code](https://github.com/Jeroen6/SparkCore_ThermoWeer/blob/master/main.cpp)

The most annoying part is that a faulty request, something like _GET /blard HTTP/1.0\r\n\r\n_, receives an 404 which is read completely and displayed on terminal and state 5 (parsing data)

\*Example on my website

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [January 28, 2014, 9:15pm UTC](https://community.particle.io/t/http-request-issue/2436/2 "2014-01-28T21:15:01Z")

</div>

Hi @Jeroen3, this is something I encounted yesterday as well… and the solution is here…  
[https://github.com/spark/core-firmware/pull/67](https://github.com/spark/core-firmware/pull/67)

If you build your code locally you can just replace those two edited files and it should work.

I don’t think it’s the complete fix, but it gets us downloading all of the data 😄

---

<div class="post-metadata">

**Author:** ![Jeroen3](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@Jeroen3](https://community.particle.io/u/Jeroen3)\
**Post date:** [January 28, 2014, 9:21pm UTC](https://community.particle.io/t/http-request-issue/2436/3 "2014-01-28T21:21:26Z")

</div>

Why does’t that bug change a 404 response, while affecting a 200 response massively?

Edit:  
Because a 404 is about 965 bytes long and a 200 response is only 170 bytes.  
I added 64 dots to the end of the page and now it works!

There must be an issue in the used circular buffer. (Probably not using [this one](https://mbed.org/users/jeroen3/code/xIFO/) 😉)

---

<div class="post-metadata">

**Author:** ![BDub](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bdub/32/5137_2.png) [@BDub](https://community.particle.io/u/BDub)\
**Post date:** [January 28, 2014, 10:14pm UTC](https://community.particle.io/t/http-request-issue/2436/4 "2014-01-28T22:14:39Z")

</div>

I don’t think that’s the answer… because I have been experimenting with 200 responses that return variable amounts of data anywhere from a couple hundred bytes to 1500 bytes. It’s some issue with how the data is buffered from the CC3000 and how the TCP library extracts it. You could be right about a bad circular buffer though 😉

---

<div class="post-metadata">

**Author:** ![Jeroen3](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@Jeroen3](https://community.particle.io/u/Jeroen3)\
**Post date:** [January 28, 2014, 10:23pm UTC](https://community.particle.io/t/http-request-issue/2436/5 "2014-01-28T22:23:10Z")

</div>

I guess the stack hash issues, just now it bricked itself again.

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [January 29, 2014, 3:49am UTC](https://community.particle.io/t/http-request-issue/2436/6 "2014-01-29T03:49:16Z")

</div>

I had better luck with a minor code change I explained in a post over here:

> **[TCP Client not reading anything](https://community.particle.io/t/tcp-client-not-reading-anything/2427/15)**
>
> I just want to report back a minor success. Remember in the early days we all noticed that TCPClient.available() was returning a boolean rather than a count of bytes? Well the recent changes fixed this and it must be related to the TCPClient...

Hope it works for you!

---

<div class="post-metadata">

**Author:** ![Jeroen3](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@Jeroen3](https://community.particle.io/u/Jeroen3)\
**Post date:** [January 29, 2014, 11:29pm UTC](https://community.particle.io/t/http-request-issue/2436/7 "2014-01-29T23:29:00Z")

</div>

I’ve just discovered that the succes rate of a TCP conversation depends on the size of the packet sent back and the time delays between TCP lib calls.
