#include <Windows.h>
#include <WinInet.h>
#include <tchar.h>
#include<iostream>
#include<stdio.h>
#include<conio.h>
#pragma comment (lib, "Wininet.lib")
#pragma comment (lib, "urlmon.lib")
void Request(LPSTR data);
int main(int argc, _TCHAR* argv[])
{
char data[1024];
char* posturi ="{\"type\":\"Point\",\"coordinates\":[-105.01628,39.57422]}";
wsprintfA( data, posturi);
wsprintfA(data,posturi);
Request(data);
system("pause");
return 0;
}
void Request(LPSTR data)
{
try{
//Retrieve default http user agent
char httpUseragent[512];
DWORD szhttpUserAgent = sizeof(httpUseragent);
//ObtainUserAgentString( 0, httpUseragent, &szhttpUserAgent );
char m[5];
HINTERNET internet = InternetOpen(_T(" Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if(internet==NULL)
{
std::cout<<"InternetOpen failed";
}
if(internet != NULL)
{
HINTERNET connect = InternetConnect(internet, _T("geojsonlint.com"), INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if(connect==NULL)
{
std::cout<<"InternetConnect failed";
}
if(connect != NULL)
{
HINTERNET request = HttpOpenRequest(connect, _T("POST"), _T("/validate"), _T("HTTP/1.1"), NULL, NULL,
INTERNET_FLAG_HYPERLINK | INTERNET_FLAG_IGNORE_CERT_CN_INVALID |
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |
INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP |
INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS |
INTERNET_FLAG_NO_AUTH |
INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_NO_UI |
INTERNET_FLAG_PRAGMA_NOCACHE |
INTERNET_FLAG_RELOAD, NULL);
if(request==NULL)
{
std::cout<<"HttpOpenRequest failed";
}
if(request != NULL)
{
int datalen = 0;
if(data != NULL) datalen = strlen(data);
LPCWSTR RH=_T("Connection: keep-Alive\r\n");
HttpAddRequestHeaders(request,RH,_tcslen(RH),HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
LPCWSTR RH1=_T("Content-Type: application/json\r\n");
HttpAddRequestHeaders(request,RH1,_tcslen(RH1),HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
LPCWSTR RH3=_T("Accept-Language: en-US,en;q=0.8\r\n");
HttpAddRequestHeaders(request,RH3,_tcslen(RH3),HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
LPCWSTR RH4=_T("Accept: */*\r\n");
HttpAddRequestHeaders(request,RH4,_tcslen(RH4),HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
LPCWSTR RH5=_T("Accept-Encoding: gzip,deflate,sdch\r\n");
HttpAddRequestHeaders(request,RH5,_tcslen(RH5),HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
HttpSendRequestA(request, NULL, 0, data, datalen);
DWORD StatusCode = 0;
DWORD StatusCodeLen = sizeof(StatusCode);
HttpQueryInfo(request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &StatusCode, &StatusCodeLen, NULL);
if(StatusCode==200)
{
std::cout<<"Sucess=200";
}
else
{
std::cout<<"failed="<<StatusCode;
}
InternetCloseHandle(request);
}
}
InternetCloseHandle(connect);
}
InternetCloseHandle(internet);
}
catch(...) {}
} Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++ and start coding!
OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout << "Enter name:";
getline (cin, name);
cout << "Hello " << name;
return 0;
}
C++ is a widely used middle-level programming language.
When ever you want to perform a set of operations based on a condition If-Else is used.
if(conditional-expression) {
//code
}
else {
//code
}
You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.
Switch is an alternative to If-Else-If ladder.
switch(conditional-expression){
case value1:
// code
break; // optional
case value2:
// code
break; // optional
......
default:
code to be executed when all the above cases are not matched;
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while (condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.
return_type function_name(parameters);
function_name (parameters)
return_type function_name(parameters) {
// code
}