main.cpp
来自「网路编程 一些函数的使用方法」· C++ 代码 · 共 55 行
CPP
55 行
#include <string>
#include <vector>
#include <iostream>
using namespace std;
#include <windows.h>
#include <wininet.h>
#include "web.h"
using namespace openutils;
int main() {
char name[51];
char rate[12];
char amt[12];
cout << "Welcome to the On-line interest calculator. " << endl;
cout << "Enter name: ";
gets(name);
cout << "Enter rate: ";
cin >> rate;
cout << "Enter amount: ";
cin >> amt;
try {
WebForm wf;
// the web server name is set
wf.setHost("http://localhost:8080");
// the script to be executed on the web server...
wf.setScriptFile("/banking/servlet/InterestServlet");
cout << "Contacting " << wf.getHost() << "..." << endl;
// form variables are added to the request object
wf.putVariable("name",name);
wf.putVariable("rate",rate);
wf.putVariable("amt",amt);
cout << "Sending request..." << endl;
// data is encoded and send to the server script
// for processing
wf.sendRequest();
// reading back any response
char response[101];
if(wf.getResponse(response,100)) {
cout << endl << response << endl;
}else {
cout << "No response from server" << endl;
}
}catch(WebFormException ex) {
cout << ex.getMessage() << endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?