can't get request result with WIFI Shield.

first, i can’t speak english.
this article is written by google translator.

My wifi-shield firmware version is 1.0.2

httpRequest() - success
httpRequest2() - fail

Both work all that well in pc web browser.
why did it failed?

#include <WiFi.h>

unsigned long lastConnectionTime = 0;
unsigned long postingInterval = 10L * 3000L; //interval 시간

WiFiClient clientAPI; // Wifi clientAPI For API

bool WifiConnect()
{
  int status = WL_IDLE_STATUS;
  if ( WiFi.status() == WL_NO_SHIELD )
  {
    printDebugMessage("Wifi Shiled Failed ");
    return false;
  }
  if ( status != WL_CONNECTED)
  {
    printDebugMessage("Connect Wifi SSID : ");
    printDebugMessage(ssid);
    status = WiFi.begin(ssid, pass);
  }

  if ( status == WL_CONNECTED )
    return true;
  else
  {
    printDebugMessage("Unhandled Error in Wifi Connect");
    return false;
  }
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while ( !WifiConnect() )
  {
    printDebugMessage("Try Connect....");
    delay(10000);
  }
  printDebugMessage("Connect Complete");
}


void loop() {

  boolean bResult = false;
  if (millis() - lastConnectionTime > postingInterval) { //interval 시간이 충족되었다면
    httpRequest2(); //데이터 호출
  }
  while(clientAPI.available())
  {
    char text = clientAPI.read();
    Serial.print(text);
  }

}

void httpRequest( )
{
 clientAPI.stop();
 Serial.println("connecting...");
 if (clientAPI.connect(ServerUrl, 80)) {
   clientAPI.println("GET /data/2.5/weather?q=london&units=metric&APPID=0fea272f894d18e6e1e1908c82546d99");
   clientAPI.println("HOST: api.openweathermap.org");
   clientAPI.println("User-Agent: ArduinoWiFi/1.1");
   clientAPI.println("Connection: close");
   clientAPI.println();
   lastConnectionTime = millis();
 }
 else
 {
   printDebugMessage("Web Request failed");
 }
}

void httpRequest2( )
{
 clientAPI.stop();
 Serial.println("connecting...22");
 if (clientAPI.connect(ServerUrl, 80)) {

   clientAPI.println("GET /data/2.5/forecast/weather?q=london&units=metric&cnt=1&APPID=0fea272f894d18e6e1e1908c82546d99");
   clientAPI.println("HOST: api.openweathermap.org");
   clientAPI.println("User-Agent: ArduinoWiFi/1.1");
   clientAPI.println("Connection: close");
   clientAPI.println();
   
   lastConnectionTime = millis();
   
 }
 else
 {
   printDebugMessage("Web request failed 2");
   
 }
}

Post the entire sketch. If you are not reading the response from the server and closing the connection, that could cause you problems with any subsequent connection attempts.

edit: You are not reading the server response correctly. The server may not (and usually doesn't) respond immediately, so you must use this:

// while the server is still sending packets
while(clientAPI.connected())  
{
  // read the next packet
  while(clientAPI.available())
  {
    char text = clientAPI.read();
    Serial.print(text);
  }
}
// when the server closes, close your end
clientAPI.stop();

The connection is failing on a second attempt. If you repeat just the first connection, does it also fail?

Your code throws a couple errors. serverUrl is not declared in this scope and printDebugMessage is missing. ??

printDebugMessage() is just Serial.println();
and

I apologize for not fully attached to the source code.

and

char ServerUrl = "api.openweathermap.org";

I apologize for not fully attached to the source code.

Your OP code has more errors than that. You are attempting to read from a connection that was not established.

  if (millis() - lastConnectionTime > postingInterval) { //interval 시간이 충족되었다면
    httpRequest2(); //데이터 호출
  }
  // you haven't sent a request very iteration of loop
  // and you are attempting to read from it
  while(clientAPI.available())
  {
    char text = clientAPI.read();
    Serial.print(text);
  }
#include <WiFi.h>
#include <SoftwareSerial.h>

SoftwareSerial BTSerial(2, 3);   //bluetooth module Tx:Digital 2 Rx:Digital 3

struct WeatherData
{
  int dt;
  int weatherCode ;


};
WeatherData wData[14] = {0,};


char ssid[] = "xxxxx";     //  Wifi
char pass[] = "xxxxxxx";  // 네트워크 보안키
char ServerUrl[] = "api.openweathermap.org";

unsigned long lastConnectionTime = 0;
unsigned long postingInterval = 10L * 3000L; //interval 시간

WiFiClient clientAPI; // Wifi clientAPI For API


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while ( !WifiConnect() )
  {
    printDebugMessage("Try Connect....");
    delay(10000);
  }
  printDebugMessage("Connect Complete");
}



void loop() {

  boolean bResult = false;
  if (millis() - lastConnectionTime > postingInterval) { //interval 시간이 충족되었다면
    httpRequest2(); //데이터 호출

  while(clientAPI.connected())
  {
      while(clientAPI.available())
    {
     char text = clientAPI.read();
    Serial.print(text);
    }
  }

  
  }
 clientAPI.stop();


//
//  boolean bResult = false;
//  if (millis() - lastConnectionTime > postingInterval) { //interval 시간이 충족되었다면
//    bResult = httpRequest2(); //데이터 호출
//  }
//  if (bResult)
//  {
//     anlayzeWeatherAPI(clientAPI);
//    for ( int i = 0; i < 14; i++ )
//    {
//      Serial.print(wData[i].weatherCode);
//      Serial.print(" ");
//      Serial.print(wData[i].dt);
//      Serial.println();
//    }   
//  }
}









void printDebugMessage( String Message ) {
  Serial.println(Message);
}

bool WifiConnect()
{
  int status = WL_IDLE_STATUS;
  if ( WiFi.status() == WL_NO_SHIELD )
  {
    printDebugMessage("Wifi Shiled Failed ");
    return false;
  }
  if ( status != WL_CONNECTED)
  {
    printDebugMessage("Connect Wifi SSID : ");
    printDebugMessage(ssid);
    status = WiFi.begin(ssid, pass);
  }

  if ( status == WL_CONNECTED )
    return true;
  else
  {
    printDebugMessage("Unhandled Error in Wifi Connect");
    return false;
  }
}

void httpRequest( )
{
  clientAPI.stop();
  Serial.println("connecting...");
  if (clientAPI.connect(ServerUrl, 80)) {
    clientAPI.println("GET /data/2.5/weather?q=Gwangju&units=metric&APPID=0fea272f894d18e6e1e1908c82546d99");
    clientAPI.println("HOST: api.openweathermap.org");
    clientAPI.println("User-Agent: ArduinoWiFi/1.1");
    clientAPI.println("Connection: close");
    clientAPI.println();
    lastConnectionTime = millis();
    } 
  else
  {
    printDebugMessage("Web Request failed");
  }
}
void httpRequest2( )
{
  clientAPI.stop();
  Serial.println("connecting...22");
  if (clientAPI.connect(ServerUrl, 80)) {

    clientAPI.println("GET /data/2.5/forecast/weather?q=London&units=metric&cnt=1&APPID=0fea272f894d18e6e1e1908c82546d99");
    clientAPI.println("HOST: api.openweathermap.org");
    
    clientAPI.println("User-Agent: ArduinoWiFi/1.1");
    clientAPI.println("Connection: close");
    clientAPI.println();
    
    lastConnectionTime = millis();
    
  }
  else
  {
    printDebugMessage("Web request failed 2");
    
  }
}

thx for help.
how can i read from that connection?

This reads and displays the response from the server connection.

  while(clientAPI.connected())
  {
      while(clientAPI.available())
      {
        char text = clientAPI.read();
        Serial.print(text);
      }
  }

i've still failed request. TT
this not working TT sorry.

Maybe you need a bit more experience with the WiFi shield before attempting two connections.

I’d like to stick around, but I’m going surfing. Be back in a couple hours.

thx for yout helping.

When I type http:// followed by the server followed by the data in the GET request into the address bar of the browser, I get:

{"cod":401, "message": "Invalid API key. Please see Frequently Asked Questions - OpenWeatherMap for more info."}

You should be able to connect if your code is correct. If the request is faulty, that will not prevent a connection.

Have you tried connecting to a "regular" website like Google?