Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 567247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:03:46+00:00 2026-05-13T13:03:46+00:00

I am writing an arduino library to post http request on web. I am

  • 0

I am writing an arduino library to post http request on web.

I am using the String class from http://arduino.cc/en/Tutorial/TextString

My code is behaving strangely when I am referring to my defined string objects after a function call.

Here actually I am trying to get the body of my GET request and removing the http headers from the http GET request’s response.

Following is the description:

Method Call:

  String body;  
  if(pinger.Get(host,path,&body))
  {
    Serial.println("Modified String Outside :");
    Serial.println(body);
    Serial.println();
    Serial.println("Modified String Outside Address");
    Serial.println((int)&body);
  }

Output

Modified String Outside :
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html
Content-Length: 113
Date: Wed, 13 Jan 2010 14:36:28 GMT

<html>
<head>
<title>Ashish Sharma
</title>
</head>
<body>
Wed Jan 13 20:06:28 IST 2010
</body>
</html>


Modified String Outside Address
2273

Method Description:

bool Pinger::Get(String host, String path, String *response) {
    bool connection = false;
    bool status = false;

    String post1 = "GET ";
    post1 = post1.append(path);
    post1 = post1.append(" HTTP/1.1");

    String host1 = "Host: ";
    host1 = host1.append(host);

    for (int i = 0; i < 10; i++) {
        if (client.connect()) {
            client.println(post1);
            client.println(host1);
            client.println();
            connection = true;
            break;
        }
    }

    int nlCnt = 0;
    while (connection) {
        if (client.available()) {
            int c = client.read();
            response->append((char) c);
            if (c == 0x000A && nlCnt == 0) {
                nlCnt++;
                if (response->contains("200")) {
                        status = true;
                        continue;
                    } else {
                        client.stop();
                        client.flush();
                        break;
                    }   
            }
        }
        if (!client.connected()) {
            client.stop();
            connection = false;
        }
    }           
    response = &response->substring(response->indexOf("\n\r\n"),response->length());    
    Serial.println("Modified String: ");
    Serial.println(*response);  

    Serial.println();
    Serial.print("Modified String Address: ");
    Serial.println((int)&response);
    return status;
}

Output:

Modified String: 
Ø
<html>
<head>
<title>Ashish Sharma
</title>
</head>
<body>
Wed Jan 13 20:06:28 IST 2010
</body>
</html>

Modified String Address: 2259

As can be seen from the example the string reference object is giving me the correct string inside the Get method but the reference of the string contents change when the Get method returns.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:03:47+00:00Added an answer on May 13, 2026 at 1:03 pm

    If I understood correctly your code, you probably would want to do something like this:

    *response = response->substring(response->indexOf("\n\r\n"),response->length());
    

    instead of

    response = &response->substring(response->indexOf("\n\r\n"),response->length());
    

    Also there’s probably no need to pass in a pointer ( reference would probably make the code look much nicer ).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing the code for the user authentication portion of a web site (including account
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
I want to write a library for my Arduino(header and class files), but I
After writing and reading an xml string to and from a stream, it ceases
I'm writing a class for the Arduino. It's been going well so far, but
Writing a code that does the following: Adds a mouse listener to a web-page
I'm writing a DSL in Ruby to control an Arduino project I'm working on;
I'm writing a program that needs to take input from an XBox 360 controller.
Following up on this comment from the question Writing firmware: assembly or high level?
Writing my first JQTouch app. When I go from #login to #home , a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.