Post the file with sim900

hello,
I am trying to post text file in http server but i am getting 500 response all time. please guide me.
thank you

code:

#define SIM900 Serial1
#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {
SIM900.begin(9600); /* Define baud rate for software serial communication /
Serial.begin(9600); /
Define baud rate for serial communication */
Serial.print(“starting…”);

Serial.print(“Initializing SD card…”);

if (!SD.begin(4)) {
Serial.println(“initialization failed!”);
return;
}
Serial.println(“initialization done.”);

  }

void loop() {

Serial.println(“HTTP post method :”);
Serial.print(“AT\r\n”);
SIM900.println(“AT”); /* Check Communication /
delay(5000);
ShowSerialData(); /
Print response on the serial monitor /
delay(5000);
/
Configure bearer profile 1 /
Serial.print(“AT+SAPBR=3,1,“CONTYPE”,“GPRS”\r\n”);
SIM900.println(“AT+SAPBR=3,1,“CONTYPE”,“GPRS””); /
Connection type GPRS /
delay(5000);
ShowSerialData();
delay(5000);
Serial.print(“AT+SAPBR=3,1,“APN”,“www”\r\n”);
SIM900.println(“AT+SAPBR=3,1,“APN”,“www””); /
APN of the provider /
delay(5000);
ShowSerialData();
delay(5000);
Serial.print(“AT+SAPBR=1,1\r\n”);
SIM900.println(“AT+SAPBR=1,1”); /
Open GPRS context /
delay(5000);
ShowSerialData();
delay(5000);
Serial.print(“AT+SAPBR=2,1\r\n”);
SIM900.println(“AT+SAPBR=2,1”); /
Query the GPRS context /
delay(5000);
ShowSerialData();
delay(5000);
Serial.print(“AT+HTTPINIT\r\n”);
SIM900.println(“AT+HTTPINIT”); /
Initialize HTTP service /
delay(5000);
ShowSerialData();
delay(5000);
Serial.print(“AT+HTTPPARA=“CID”,1\r\n”);
SIM900.println(“AT+HTTPPARA=“CID”,1”); /
Set parameters for HTTP session */
delay(5000);
ShowSerialData();
delay(5000);

Serial.print("AT+HTTPPARA=“URL”,"http://ptsv2.com/t/eu87r-1529326906/post"\r\n");
SIM900.println(“AT+HTTPPARA=“URL”,“http://ptsv2.com/t/eu87r-1529326906/post””); /* Set parameters for HTTP session */

delay(5000);
ShowSerialData();
delay(5000);

  Serial.println("AT+HTTPPARA=\"CONTENT\",\"multipart/form-data; boundary=--acebxz\"");  
SIM900.println("AT+HTTPPARA=\"CONTENT\",\"multipart/form-data; boundary=--acebxz\"");

delay(5000);
delay(5000);
ShowSerialData();
delay(5000);
sendfile(); // sending the text file content in server
delay(5000);
ShowSerialData();
delay(5000);
Serial.print(“AT+HTTPACTION=1\r\n”);
SIM900.println(“AT+HTTPACTION=1”); /* Start POST session */
delay(5000);

ShowSerialData();
delay(5000);
delay(5000);
delay(5000);
delay(5000);
ShowSerialData();
delay(5000);
Serial.print(“AT+HTTPTERM\r\n”);
SIM900.println(“AT+HTTPTERM”); /* Terminate HTTP service /
delay(5000);
ShowSerialData();
delay(5000);
Serial.print(“AT+SAPBR=0,1\r\n”);
SIM900.println(“AT+SAPBR=0,1”); /
Close GPRS context */
delay(5000);
ShowSerialData();
delay(5000);
}

void ShowSerialData()
{
Serial.print("\n");
while(SIM900.available()!=0) /* If data is available on serial port /
Serial.print(char (SIM900.read())); /
Print character received on to the serial monitor */
}

//sending the file in multipart form data
void sendfile(void)
{
myFile = SD.open(“at.txt”);
if (myFile) {
Serial.println("\n open done at.txt");
//send file length
Serial.print(“AT+HTTPDATA=”+String(myFile.size()+105)+",50000");
SIM900.println(“AT+HTTPDATA=”+String(myFile.size()+105)+",50000");
delay(2000);
ShowSerialData();
delay(2000);

// read from the file until there’s nothing else in it:
Serial.print("–acebxz\n");
SIM900.println("–acebxz");

Serial.print(“Content-Disposition: form-data; name=“fi”; filename=“at.txt”\n”);
SIM900.print(“Content-Disposition: form-data; name=“fi”; filename=“at.txt”\n”);

Serial.print("Content-Type: text/plain\n");
SIM900.print("Content-Type: text/plain\n");

myFile.close();
myFile = SD.open(“at.txt”);
char op[500];
int j=0;
while (myFile.available())
{
byte ch=myFile.read();
op[j++]=ch;
}
op[j]=’\0’;
myFile.close();

Serial.write(op);
SIM900.write(op);
Serial.print("\n–acebxz\n");
SIM900.print("\n–acebxz\n");
Serial.print(“File Data sending done\n”);

   //myFile.close();

} else {
// if the file didn’t open, print an error:
Serial.println(“file not open at.txt”);
}

}

Hi,
I havent come across this Content-Disposition: header.
You can follow my video on HTTP post.


Example code is on my blog , link to blog in video description.

hi,
I am following link i am getting same error 500. in that code i am using boundary form can please tell what i did wrong.

SIM900.println(“AT+HTTPPARA=“CONTENT”,“multipart/form-data; boundary=–acebxz””);
SIM900.println(“AT+HTTPDATA=”+String(myFile.size()+105)+",50000");
SIM900.println("–acebxz");
SIM900.print(“Content-Disposition: form-data; name=“fi”; filename=“at.txt”\n”);
SIM900.print(“Content-Type: text/plain\n”);
SIM900.print(data);
SIM900.print("\n–acebxz\n");

Try testing with Fiddler software first. If it works just copy that data in code and try next.
The way you are doing is different that what i did.

hello sir,
thank you for your response i used fiddler also and i am copying the same header. what that software executing but i am getting same issue. it’s continue showing me 500 response. please guide me.

Try the code using terminal first then try using your code.
Enter AT commands using terminal and then try experimenting using code. Then you can make sure if everything working.

hello Ravid i am working with the Galileo Board first generation, also i have a couple of shields to handle GPS adafruit breakout v3 and GPRS shield Seeed V3 with a Sim900 integrated. The problem i have is when i try to send HTTP request. here i post the my code:
void http_get() {
digitalWrite(sel, LOW);

Serial1.flush();
Serial.flush();

Serial.print("Selector: ");
Serial.println(digitalRead(sel));

delay(10000);
Serial1.println(“AT+HTTPINIT\r\n”);
delay(2000);
toSerial();

Serial1.println(“AT+HTTPPARA=“CID”,1\r\n”);
delay(2000);
toSerial();

Serial1.println(url);
/*url = AT+HTTPPARA=“URL”,"http://a web side URL followed by this parameter/AA112BB/?lat=“XXgXXmXXsXXXXmili&lon=XXgXXmXsXXXXmili&hour=XXhXXmXXs&date=29Dd8Mm18Yy” */

delay(2000);
toSerial();

Serial1.println(“AT+HTTPACTION=0\r\n”);
delay(6000);
toSerial();
Serial1.println("");

Serial1.println(“AT+HTTPREAD\r\n”);
delay(6000);
toSerial();
Serial1.println("");

Serial1.println(“AT+HTTPTERM\r\n”);
toSerial();
delay(300);
Serial1.println("");
delay(10000);

Serial.print("Selector al finalizar: ");
Serial.println(digitalRead(sel));

}
void toSerial() {
Serial1.flush();
Serial.flush();
while(Serial1.available()!=0) { // Checks if Serial1 information is available and not null
Serial.write(Serial1.read()); // Print available Serial1 information in Serial port
}
}

the answer i got is this:
AT+HTTPINIT

ERROR
AT+HTTPPARA=“CID”,1

OK
url = AT+HTTPPARA=“URL”,"http://a web side URL followed by this parameter/AA112BB/?lat=“XXgXXmXXsXXXXmili&lon=XXgXXmXsXXXXmili&hour=XXhXXmXXs&date=29Dd8Mm18Yy”

ERROR
AT+HTTPACTION=0

ERROR

AT+HTTPREAD

OK.

my GPRS setup is this:

T+CGDCONT?

+CGDCONT: 1,“IP”,“internet.movistar.ve”,“0.0.0.0”,0,0
+CGDCONT: 3,“IP”,"",“0.0.0.0”,0,0

OK
AT+CGPADDR=?

+CGPADDR: (1,2,3)

OK
AT+CGDCONT=1,“IP”,“www”,"",0,0

OK
AT+CGPADDR=?

+CGPADDR: (1,2,3)

OK
AT+IPR=9600

OK
AT+CGATT?

+CGATT: 1

OK
AT

OK
AT+CFUN=1

OK
AT+CPIN?

+CPIN: READY

OK
AT+SAPBR=3,1,“CONTYPE”,“GPRS”

OK
AT+SAPBR=3,1,“APN”,“www”

OK
AT+SAPBR=1,1

OK

Hi @Luis_Gabriel_Lucena Please create separate thread to address your problem.