
关于http图像传输的问题
http是怎么对图片进行传输的,我现在是将图片的二进制码放在报文里面的实体里面,但是报的错误是413(实体太大),请问图片放在报文要怎么做啊,使用什么编码...
http是怎么对图片进行传输的,我现在是将图片的二进制码放在报文里面的实体里面,但是报的错误是413(实体太大),请问图片放在报文要怎么做啊,使用什么编码
展开
1个回答
2017-04-27
展开全部
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <unistd.h>
#include <sys/socket.h>
#include <string.h>
#include <fcntl.h>
int main(void) {
struct sockaddr_in sin;
struct sockaddr_in cin;
int lfd;
int afd;
int ffd;
int rlen;
socklen_t len;
char buf[1024];
bzero(&sin,sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(8000);
sin.sin_addr.s_addr = INADDR_ANY;
lfd = socket(AF_INET,SOCK_STREAM,0);
if(lfd < 0) {
perror("socket");
exit(1);
}
if(bind(lfd,(struct sockaddr *)&sin,sizeof(sin)) == -1) {
perror("bind");
exit(1);
}
listen(lfd,10);
while(1) {
bzero(buf,1024);
afd = accept(lfd,(struct sockaddr *)&cin,&len);
if(afd < 0) {
perror("afd");
exit(1);
}
if(recv(afd,buf,1024,0) < 0) {
perror("recv");
exit(1);
}
printf("%s",buf);
write(afd,"HTTP/1.1 200 OK\r\n",strlen("HTTP/1.1 200 OK\r\n"));
write(afd,"Content-Disposition: attachment; filename=aa.jpeg",strlen("Content-Disposition: attachment; filename=aa.jpeg"));
write(afd,"\r\n\r\n",strlen("\r\n\r\n"));
ffd = open("/home/jimmy-cao/图片/a.jpeg",O_RDONLY);
while((rlen = read(ffd,buf,1024)) > 0) {
write(afd,buf,rlen);
}
fsync(afd);
close(afd);
}
return EXIT_SUCCESS;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <unistd.h>
#include <sys/socket.h>
#include <string.h>
#include <fcntl.h>
int main(void) {
struct sockaddr_in sin;
struct sockaddr_in cin;
int lfd;
int afd;
int ffd;
int rlen;
socklen_t len;
char buf[1024];
bzero(&sin,sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(8000);
sin.sin_addr.s_addr = INADDR_ANY;
lfd = socket(AF_INET,SOCK_STREAM,0);
if(lfd < 0) {
perror("socket");
exit(1);
}
if(bind(lfd,(struct sockaddr *)&sin,sizeof(sin)) == -1) {
perror("bind");
exit(1);
}
listen(lfd,10);
while(1) {
bzero(buf,1024);
afd = accept(lfd,(struct sockaddr *)&cin,&len);
if(afd < 0) {
perror("afd");
exit(1);
}
if(recv(afd,buf,1024,0) < 0) {
perror("recv");
exit(1);
}
printf("%s",buf);
write(afd,"HTTP/1.1 200 OK\r\n",strlen("HTTP/1.1 200 OK\r\n"));
write(afd,"Content-Disposition: attachment; filename=aa.jpeg",strlen("Content-Disposition: attachment; filename=aa.jpeg"));
write(afd,"\r\n\r\n",strlen("\r\n\r\n"));
ffd = open("/home/jimmy-cao/图片/a.jpeg",O_RDONLY);
while((rlen = read(ffd,buf,1024)) > 0) {
write(afd,buf,rlen);
}
fsync(afd);
close(afd);
}
return EXIT_SUCCESS;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?

2023-08-29 广告
"StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,I...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询