 |
Club Builder Foro de C++Builder en español
|
| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
likibuay Master


Registrado: 24 Abr 2006Mensajes: 190Ubicación: COLOMBIA
|
Publicado: Lun 07 Nov, 2016 4:59 pm Asunto: InternetOpenA InternetConnectA HttpOpenR InternetR wininet.h |
|
|
buenas! tratando de enviar sms utilizando una API de un proveedor y el código del mismo, me da error? que podría ser? trabajo con B6
agregue:
| escafandra escribió: | | Debes añadir la ruta de librerías $(BCB)\Lib\PSDK\ para que se pueda enlazar Wininet.lib. Esto lo añades en las opciones del proyecto->Directories /Conditionals->Library Path.. |
| Código: | #include<iostream>
#include<sstream>
#include<windows.h>
#include<wininet.h>
using namespace std;
string encode(string url);
int main(int argc, char** argv)
{
string host = "http://xxxx";
int port = 80;
string username = "email@mail.com";
string password = "XXXXXXX";
string message = "Test message";
string originator = "123456789";
string recipient = "REMITENTE";
stringstream url;
url << "/api?username=" << encode(username);
url << "&password=" << encode(password);
url << "&sender=" << encode(recipient);
url << "&msisdn=" << encode(originator);
url << "&message=" << encode(message);
// Create socket.
HINTERNET inet = InternetOpen("xxxx", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
// Open connection and bind it to the socket.
HINTERNET conn = InternetConnect(inet, host.c_str() , port, NULL, NULL,
INTERNET_SERVICE_HTTP, 0, 0);
// Open the HTTP request
HINTERNET sess = HttpOpenRequest(conn, "GET", url.str().c_str(), "HTTP/1.1",
NULL, NULL, INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD, 0);
// Check errors
int error = GetLastError();
if(error == NO_ERROR)
{
// Send HTTP request.
HttpSendRequest(sess, NULL, 0, NULL,0);
// Receive HTTP response.
int size = 1024;
char *buffer = new char[size + 1];
DWORD read;
int rsize = InternetReadFile(sess, (void *)buffer, size, &read);
string s = buffer;
s = s.substr(0, read);
// Check statuscode
int pos = s.find("<code>0</code>");
// If statuscode is 0, write "Message sent." to output
// else write "Error."
if(pos > 0) cout << "Message sent." << endl;
else cout << "Error." << endl;
}
system("pause");
}
// encoding converts characters that are not allowed in a URL into character-entity equivalent.
string encode(string url)
{
char *hex = "0123456789abcdef";
stringstream s;
for(unsigned int i = 0; i < url.length(); i++)
{
byte c = (char)url.c_str()[i];
if( ('a' <= c && c <= 'z')
|| ('A' <= c && c <= 'Z')
|| ('0' <= c && c <= '9') ){
s << c;
} else {
if(c == ' ') s << "%20";
else
s << '%' << (hex[c >> 4]) << (hex[c & 15]);
}
}
return s.str();
} |
me da estos errores:
| Cita: | [Linker Error] Unresolved external 'InternetOpenA' referenced from C:\USERS\JABRAHAMS\DESKTOP\LABSMOBILE SMS\UNIT1.OBJ
[Linker Error] Unresolved external 'InternetConnectA' referenced from C:\USERS\JABRAHAMS\DESKTOP\LABSMOBILE SMS\UNIT1.OBJ
[Linker Error] Unresolved external 'HttpOpenRequestA' referenced from C:\USERS\JABRAHAMS\DESKTOP\LABSMOBILE SMS\UNIT1.OBJ
[Linker Error] Unresolved external 'HttpSendRequestA' referenced from C:\USERS\JABRAHAMS\DESKTOP\LABSMOBILE SMS\UNIT1.OBJ
[Linker Error] Unresolved external 'InternetReadFile' referenced from C:\USERS\JABRAHAMS\DESKTOP\LABSMOBILE SMS\UNIT1.OBJ
|
_________________ ><(((((º> From °l||l° §ÂN ÅNЮ€$ i§Lã$ °l||l°
_____________________
Ultima edición por likibuay el Lun 07 Nov, 2016 9:49 pm, editado 1 vez |
|
| Volver arriba |
|
 |
_Leo Site Admin

Registrado: 11 Ago 2002Mensajes: 1875Ubicación: Lanzarote - Islas Canarias (España)
|
Publicado: Lun 07 Nov, 2016 7:31 pm Asunto: |
|
|
Hola, si ya hiciste lo que te dijo escafandra es posible que te falte enlazar la librería "WinInet.lib", puedes hacerlo añadiendo la siguiente línea debajo de los includes:
| Código: | #pragma comment(lib, "wininet.lib") |
O bien añadirla desde el menú: Project -> Add to Project... |
|
| Volver arriba |
|
 |
likibuay Master


Registrado: 24 Abr 2006Mensajes: 190Ubicación: COLOMBIA
|
Publicado: Lun 07 Nov, 2016 9:25 pm Asunto: |
|
|
listo, perfecto. eso era!
ya envía mensajes de texto a celulares.
muchas gracias _Leo y escafandra. _________________ ><(((((º> From °l||l° §ÂN ÅNЮ€$ i§Lã$ °l||l°
_____________________ |
|
| Volver arriba |
|
 |
|
|
No puedes publicar temas nuevos en este foro No puedes responder a temas en este foro No puedes editar tus mensajes en este foro No puedes borrar tus mensajes en este foro No puedes votar en las encuestas de este foro
|
© 2002–2026 Club Builder · Funciona con phpBB.
|