當前位置:首頁 » 操作系統 » http源碼

http源碼

發布時間: 2022-08-25 05:27:04

Ⅰ 易語言如何獲取網頁源碼 HTTP讀文件太慢而且讀出來好多網頁是亂碼 有沒有其他辦法

網頁亂碼是因為需要進行編碼轉換,詳見模塊 彗星Http模塊 ,至於慢,其它命令都一樣,這個和網路有關

Ⅱ 遠程訪問用的是http協議,下面是源代碼

結論:①string URi = "http://192.168.0.105//www/";
URi的值應該是一個URL地址吧,怎麼105後面有兩個/
②你這樣的訪問方式涉及到客戶端對伺服器端的訪問許可權問題,我沒試過以這樣的方式將文件上傳到伺服器的,而且我覺得應該不是這樣的方式。
解決方案建議:
①可以在伺服器端開通ftp功能,將文件發送到ftp里,代碼如下:
privatevoidbutton1_Click(objectsender,EventArgse)

{

WebClientw=newWebClient();

w.Credentials=newNetworkCredential("sa","sa");//登陸ftp的用戶名密碼

w.UploadFile("ftp://221.224.78.82/skdb/up.xls",@"e:\1.xls");////前面是遠程ftp文件夾路徑後面是:本地上傳的文件路徑

w.Dispose();

MessageBox.Show("上傳成功!");

}

②伺服器端有IIS的話通過WebService的方式實現文件上傳
這個方法相對比較復雜,建議用第一種,如果要採用這種的話到時我再發一個例子給你⊙﹏⊙

Ⅲ 誰知道這個網站是用什麼源碼 。http://vipcpc.tk

源碼是馬克思建站源碼

目前使用版本不清楚 但是源碼數據顯示來源於馬克思

源碼官方網站:http://www.maxcms.net/

希望能解決你的疑問

Ⅳ 如何開發自己的HttpServer-NanoHttpd源碼解讀

1.能接受HttpRequest並返回HttpResponse
2.滿足一個Server的基本特徵,能夠長時間運行

關於Http協議一般HttpServer都會聲明支持Http協議的哪些特性,nanohttpd作為一個輕量級的httpserver只實現了最簡單、最常用的功能,不過我們依然可以從中學習很多。

首先看下NanoHttpd類的start函數

[java] view plain
public void start() throws IOException {
myServerSocket = new ServerSocket();
myServerSocket.bind((hostname != null) ? new InetSocketAddress(hostname, myPort) : new InetSocketAddress(myPort));

myThread = new Thread(new Runnable() {
@Override
public void run() {
do {
try {
final Socket finalAccept = myServerSocket.accept();
registerConnection(finalAccept);
finalAccept.setSoTimeout(SOCKET_READ_TIMEOUT);
final InputStream inputStream = finalAccept.getInputStream();
asyncRunner.exec(new Runnable() {
@Override
public void run() {
OutputStream outputStream = null;
try {
outputStream = finalAccept.getOutputStream();
TempFileManager tempFileManager = tempFileManagerFactory.create();
HTTPSession session = new HTTPSession(tempFileManager, inputStream, outputStream, finalAccept.getInetAddress());
while (!finalAccept.isClosed()) {
session.execute();
}
} catch (Exception e) {
// When the socket is closed by the client, we throw our own SocketException
// to break the "keep alive" loop above.
if (!(e instanceof SocketException && "NanoHttpd Shutdown".equals(e.getMessage()))) {
e.printStackTrace();
}
} finally {
safeClose(outputStream);
safeClose(inputStream);
safeClose(finalAccept);
unRegisterConnection(finalAccept);
}
}
});
} catch (IOException e) {
}
} while (!myServerSocket.isClosed());
}
});
myThread.setDaemon(true);
myThread.setName("NanoHttpd Main Listener");
myThread.start();
}
1.創建ServerSocket,bind制定埠

2.創建主線程,主線程負責和client建立連接
3.建立連接後會生成一個runnable對象放入asyncRunner中,asyncRunner.exec會創建一個線程來處理新生成的連接。
4.新線程首先創建了一個HttpSession,然後while(true)的執行httpSession.exec。
這里介紹下HttpSession的概念,HttpSession是java里Session概念的實現,簡單來說一個Session就是一次httpClient->httpServer的連接,當連接close後session就結束了,如果沒結束則session會一直存在。這點從這里的代碼也能看到:如果socket不close或者exec沒有拋出異常(異常有可能是client段斷開連接)session會一直執行exec方法。
一個HttpSession中存儲了一次網路連接中server應該保存的信息,比如:URI,METHOD,PARAMS,HEADERS,COOKIES等。
5.這里accept一個client的socket就創建一個獨立線程的server模型是ThreadServer模型,特點是一個connection就會創建一個thread,是比較簡單、常見的socket server實現。缺點是在同時處理大量連接時線程切換需要消耗大量的資源,如果有興趣可以了解更加高效的NIO實現方式。

當獲得client的socket後自然要開始處理client發送的httprequest。

Http Request Header的parse:

[plain] view plain
// Read the first 8192 bytes.
// The full header should fit in here.
// Apache's default header limit is 8KB.
// Do NOT assume that a single read will get the entire header at once!
byte[] buf = new byte[BUFSIZE];
splitbyte = 0;
rlen = 0;
{
int read = -1;
try {
read = inputStream.read(buf, 0, BUFSIZE);
} catch (Exception e) {
safeClose(inputStream);
safeClose(outputStream);
throw new SocketException("NanoHttpd Shutdown");
}
if (read == -1) {
// socket was been closed
safeClose(inputStream);
safeClose(outputStream);
throw new SocketException("NanoHttpd Shutdown");
}
while (read > 0) {
rlen += read;
splitbyte = findHeaderEnd(buf, rlen);
if (splitbyte > 0)
break;
read = inputStream.read(buf, rlen, BUFSIZE - rlen);
}
}
1.讀取socket數據流的前8192個位元組,因為http協議中頭部最長為8192

2.通過findHeaderEnd函數找到header數據的截止位置,並把位置保存到splitbyte內。

[java] view plain
if (splitbyte < rlen) {
inputStream.unread(buf, splitbyte, rlen - splitbyte);
}

parms = new HashMap<String, String>();
if(null == headers) {
headers = new HashMap<String, String>();

}
1.http協議規定header和body之間使用兩個回車換行分割

1.Http協議第一行是Method URI HTTP_VERSION

2.後面每行都是KEY:VALUE格式的header
3.uri需要經過URIDecode處理後才能使用
4.uri中如果包含?則表示有param,httprequest的param一般表現為:/index.jsp?username=xiaoming&id=2

下面是處理cookie,不過這里cookie的實現較為簡單,所以跳過。之後是serve方法,serve方法提供了用戶自己實現httpserver具體邏輯的很好介面。在NanoHttpd中的serve方法實現了一個默認的簡單處理功能。

[java] view plain

發送response的步驟如下:

1.設置mimeType和Time等內容。
2.創建一個PrintWriter,按照HTTP協議依次開始寫入內容
3.第一行是HTTP的返回碼
4.然後是content-Type
5.然後是Date時間
6.之後是其他的HTTP Header
7.設置Keep-Alive的Header,Keep-Alive是Http1.1的新特性,作用是讓客戶端和伺服器端之間保持一個長鏈接。
8.如果客戶端指定了ChunkedEncoding則分塊發送response,Chunked Encoding是Http1.1的又一新特性。一般在response的body比較大的時候使用,server端會首先發送response的HEADER,然後分塊發送response的body,每個分塊都由chunk length\r\n和chunk data\r\n組成,最後由一個0\r\n結束。

9.如果沒指定ChunkedEncoding則需要指定Content-Length來讓客戶端指定response的body的size,然後再一直寫body直到寫完為止。

Ⅳ 如何編寫一個簡單的HTTP代理伺服器,最好提供VB源碼

VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form Form1
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口預設
Begin VB.ListBox List1
Height = 1500
Left = 120
TabIndex = 0
Top = 720
Width = 3615
End
Begin MSWinsockLib.Winsock SckGET
Index = 0
Left = 2520
Top = 360
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock Winsock1
Left = 2040
Top = 360
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim PathName As String

Sub Begin()
'啟動Winsock1,使用listen方法,聽254埠
DoEvents
Winsock1.Close
Winsock1.Protocol = sckTCPProtocol
Winsock1.LocalPort = 254

Winsock1.Listen
End Sub

Private Sub Form_Load()
'開始進行十個監聽
For i = 1 To 9
Load SckGET(i)
SckGET(i).Close
SckGET(i).Protocol = sckTCPProtocol
Next

PathName = "E:\http\" '初始化目錄
Begin
End Sub

Private Sub SckGET_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim DataReceived As String
Dim pos1 As Long, pos2 As Long
Dim QuestFile As String
Dim TData As Byte
pos1 = 0: pos2 = 0

SckGET(Index).GetData DataReceived, vbString
'處理報文
For i = 1 To Len(DataReceived)
If Mid(DataReceived, i, 1) = " " Then
If pos1 = 0 Then pos1 = i + 1 Else pos2 = i - 1: Exit For
End If
Next
'對請求的文件進行處理
On Error GoTo ExitThisSub
If pos1 <> 0 And pos2 <> 0 Then
QuestFile = Mid(DataReceived, pos1 + 1, pos2 - pos1) '得到主文件名
If QuestFile = "" Then QuestFile = "index.htm" '主頁
QuestFile = PathName & QuestFile '得到路徑
List1.AddItem SckGET(Index).LocalIP & " : GET " & QuestFile & " HTTP/1.1"
If Dir(QuestFile) = "" Then QuestFile = PathName & "404.htm" '未找到
End If

'開始發送文件信息
Open QuestFile For Binary As #1
SckGET(Index).SendData "HTTP/1.0 200 OK" + vbCrLf
SckGET(Index).SendData "MIME_version:1.0" + vbCrLf
SckGET(Index).SendData "Content_Length:" + CStr(LOF(1)) + vbCrLf
SckGET(Index).SendData "" + vbCrLf
Do While Not EOF(1)
Get #1, , TData
SckGET(Index).SendData TData
Loop

ExitThisSub:
Close #1
Begin
SckGET(Index).Close
SckGET(Index).LocalPort = 254
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Con:
For i = 0 To 9
If SckGET(i).State <> 7 Then SckGET(i).Accept requestID: Exit For '查找未用的SCK
If i = 9 And SckGET(9).State <> 7 Then Delay (1): GoTo Con '如果沒有則繼續等待
Next
End Sub

Sub Delay(Seconds&)
t& = Timer
Delay: DoEvents
If Timer < t + Seconds Then GoTo Delay
End Sub

Ⅵ http協議解析 請求行的信息怎麼提取 c語言源碼

實現步驟:
1)用Wireshark軟體抓包得到test.pcap文件
2)程序:分析pcap文件頭 -> 分析pcap_pkt頭 -> 分析幀頭 -> 分析ip頭 -> 分析tcp頭 -> 分析http信息
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<netinet/in.h>
#include<time.h>
#define BUFSIZE 10240
#define STRSIZE 1024
typedef long bpf_int32;
typedef unsigned long bpf_u_int32;
typedef unsigned short u_short;
typedef unsigned long u_int32;
typedef unsigned short u_int16;
typedef unsigned char u_int8;
//pacp文件頭結構體
struct pcap_file_header
{
bpf_u_int32 magic; /* 0xa1b2c3d4 */
u_short version_major; /* magjor Version 2 */
u_short version_minor; /* magjor Version 4 */
bpf_int32 thiszone; /* gmt to local correction */
bpf_u_int32 sigfigs; /* accuracy of timestamps */
bpf_u_int32 snaplen; /* max length saved portion of each pkt */
bpf_u_int32 linktype; /* data link type (LINKTYPE_*) */
};
//時間戳
struct time_val
{
long tv_sec; /* seconds 含義同 time_t 對象的值 */
long tv_usec; /* and microseconds */
};
//pcap數據包頭結構體
struct pcap_pkthdr
{
struct time_val ts; /* time stamp */
bpf_u_int32 caplen; /* length of portion present */
bpf_u_int32 len; /* length this packet (off wire) */
};
//數據幀頭
typedef struct FramHeader_t
{ //Pcap捕獲的數據幀頭
u_int8 DstMAC[6]; //目的MAC地址
u_int8 SrcMAC[6]; //源MAC地址
u_short FrameType; //幀類型
} FramHeader_t;
//IP數據報頭
typedef struct IPHeader_t
{ //IP數據報頭
u_int8 Ver_HLen; //版本+報頭長度
u_int8 TOS; //服務類型
u_int16 TotalLen; //總長度
u_int16 ID; //標識
u_int16 Flag_Segment; //標志+片偏移
u_int8 TTL; //生存周期
u_int8 Protocol; //協議類型
u_int16 Checksum; //頭部校驗和
u_int32 SrcIP; //源IP地址
u_int32 DstIP; //目的IP地址
} IPHeader_t;
//TCP數據報頭
typedef struct TCPHeader_t
{ //TCP數據報頭
u_int16 SrcPort; //源埠
u_int16 DstPort; //目的埠
u_int32 SeqNO; //序號
u_int32 AckNO; //確認號
u_int8 HeaderLen; //數據報頭的長度(4 bit) + 保留(4 bit)
u_int8 Flags; //標識TCP不同的控制消息
u_int16 Window; //窗口大小
u_int16 Checksum; //校驗和
u_int16 UrgentPointer; //緊急指針
}TCPHeader_t;
//
void match_http(FILE *fp, char *head_str, char *tail_str, char *buf, int total_len); //查找 http 信息函數
//
int main()
{
struct pcap_file_header *file_header;
struct pcap_pkthdr *ptk_header;
IPHeader_t *ip_header;
TCPHeader_t *tcp_header;
FILE *fp, *output;
int pkt_offset, i=0;
int ip_len, http_len, ip_proto;
int src_port, dst_port, tcp_flags;
char buf[BUFSIZE], my_time[STRSIZE];
char src_ip[STRSIZE], dst_ip[STRSIZE];
char host[STRSIZE], uri[BUFSIZE];
//初始化
file_header = (struct pcap_file_header *)malloc(sizeof(struct pcap_file_header));
ptk_header = (struct pcap_pkthdr *)malloc(sizeof(struct pcap_pkthdr));
ip_header = (IPHeader_t *)malloc(sizeof(IPHeader_t));
tcp_header = (TCPHeader_t *)malloc(sizeof(TCPHeader_t));
memset(buf, 0, sizeof(buf));
//
if((fp = fopen(「test.pcap」,」r」)) == NULL)
{
printf(「error: can not open pcap file\n」);
exit(0);
}
if((output = fopen(「output.txt」,」w+」)) == NULL)
{
printf(「error: can not open output file\n」);
exit(0);
}
//開始讀數據包
pkt_offset = 24; //pcap文件頭結構 24個位元組
while(fseek(fp, pkt_offset, SEEK_SET) == 0) //遍歷數據包
{
i++;
//pcap_pkt_header 16 byte
if(fread(ptk_header, 16, 1, fp) != 1) //讀pcap數據包頭結構
{
printf(「\nread end of pcap file\n」);
break;
}
pkt_offset += 16 + ptk_header->caplen; //下一個數據包的偏移值
strftime(my_time, sizeof(my_time), 「%Y-%m-%d %T」, localtime(&(ptk_header->ts.tv_sec))); //獲取時間
// printf(「%d: %s\n」, i, my_time);
//數據幀頭 14位元組
fseek(fp, 14, SEEK_CUR); //忽略數據幀頭
//IP數據報頭 20位元組
if(fread(ip_header, sizeof(IPHeader_t), 1, fp) != 1)
{
printf(「%d: can not read ip_header\n」, i);
break;
}
inet_ntop(AF_INET, (void *)&(ip_header->SrcIP), src_ip, 16);
inet_ntop(AF_INET, (void *)&(ip_header->DstIP), dst_ip, 16);
ip_proto = ip_header->Protocol;
ip_len = ip_header->TotalLen; //IP數據報總長度
// printf(「%d: src=%s\n」, i, src_ip);
if(ip_proto != 0×06) //判斷是否是 TCP 協議
{
continue;
}
//TCP頭 20位元組
if(fread(tcp_header, sizeof(TCPHeader_t), 1, fp) != 1)
{
printf(「%d: can not read ip_header\n」, i);
break;
}
src_port = ntohs(tcp_header->SrcPort);
dst_port = ntohs(tcp_header->DstPort);
tcp_flags = tcp_header->Flags;
// printf(「%d: src=%x\n」, i, tcp_flags);
if(tcp_flags == 0×18) // (PSH, ACK) 3路握手成功後
{
if(dst_port == 80) // HTTP GET請求
{
http_len = ip_len – 40; //http 報文長度
match_http(fp, 「Host: 「, 「\r\n」, host, http_len); //查找 host 值
match_http(fp, 「GET 「, 「HTTP」, uri, http_len); //查找 uri 值
sprintf(buf, 「%d: %s src=%s:%d dst=%s:%d %s%s\r\n」, i, my_time, src_ip, src_port, dst_ip, dst_port, host, uri);
//printf(「%s」, buf);
if(fwrite(buf, strlen(buf), 1, output) != 1)
{
printf(「output file can not write」);
break;
}
}
}
} // end while
fclose(fp);
fclose(output);
return 0;
}
//查找 HTTP 信息
void match_http(FILE *fp, char *head_str, char *tail_str, char *buf, int total_len)
{
int i;
int http_offset;
int head_len, tail_len, val_len;
char head_tmp[STRSIZE], tail_tmp[STRSIZE];
//初始化
memset(head_tmp, 0, sizeof(head_tmp));
memset(tail_tmp, 0, sizeof(tail_tmp));
head_len = strlen(head_str);
tail_len = strlen(tail_str);
//查找 head_str
http_offset = ftell(fp); //記錄下HTTP報文初始文件偏移
while((head_tmp[0] = fgetc(fp)) != EOF) //逐個位元組遍歷
{
if((ftell(fp) – http_offset) > total_len) //遍歷完成
{
sprintf(buf, 「can not find %s \r\n」, head_str);
exit(0);
}
if(head_tmp[0] == *head_str) //匹配到第一個字元
{
for(i=1; i<head_len; i++) //匹配 head_str 的其他字元
{
head_tmp[i]=fgetc(fp);
if(head_tmp[i] != *(head_str+i))
break;
}
if(i == head_len) //匹配 head_str 成功,停止遍歷
break;
}
}
// printf(「head_tmp=%s \n」, head_tmp);
//查找 tail_str
val_len = 0;
while((tail_tmp[0] = fgetc(fp)) != EOF) //遍歷
{
if((ftell(fp) – http_offset) > total_len) //遍歷完成
{
sprintf(buf, 「can not find %s \r\n」, tail_str);
exit(0);
}
buf[val_len++] = tail_tmp[0]; //用buf 存儲 value 直到查找到 tail_str
if(tail_tmp[0] == *tail_str) //匹配到第一個字元
{
for(i=1; i<tail_len; i++) //匹配 head_str 的其他字元
{
tail_tmp[i]=fgetc(fp);
if(tail_tmp[i] != *(tail_str+i))
break;
}
if(i == tail_len) //匹配 head_str 成功,停止遍歷
{
buf[val_len-1] = 0; //清除多餘的一個字元
break;
}
}
}
// printf(「val=%s\n」, buf);
fseek(fp, http_offset, SEEK_SET); //將文件指針 回到初始偏移
}

熱點內容
win8windows無法訪問 發布:2025-05-16 00:37:53 瀏覽:894
八種排序演算法 發布:2025-05-16 00:37:17 瀏覽:55
左旋螺紋數控編程實例 發布:2025-05-16 00:11:49 瀏覽:10
安卓游戲舊版本從哪個軟體下載 發布:2025-05-16 00:00:20 瀏覽:329
連接聚類演算法 發布:2025-05-15 23:55:09 瀏覽:978
工資演算法單休 發布:2025-05-15 23:52:30 瀏覽:819
超凡先鋒配置不行怎麼辦 發布:2025-05-15 23:27:54 瀏覽:532
win7取消加密 發布:2025-05-15 23:26:37 瀏覽:472
不用internet打開ftp 發布:2025-05-15 23:06:00 瀏覽:154
sql字元串取數字 發布:2025-05-15 22:57:45 瀏覽:125