|
3532
|
Programación / Desarrollo Web / Re:
|
en: 10 Febrero 2014, 08:17 am
|
Todo es probar. Miraré hoy cuando pueda que cabeceras son imprescindibles :p
Enviado desde mi ST21i mediante Tapatalk
|
|
|
3533
|
Programación / Desarrollo Web / Re: Como ver un request HTTP?
|
en: 9 Febrero 2014, 16:36 pm
|
Perdon por lo que dije de la variable, me confundí :3 Cogí con WPE los paquetes del envío de una imagen, y esta fue la cabecera,si te sirve: POST /XXX.php HTTP/1.1 User-Agent: XXXXXXXXXX Host: XXXX.es Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1 Accept-Language: es,en;q=0.9,es-ES;q=0.8 Accept-Encoding: gzip, deflate Referer: http://XXX/XXX.html Connection: Keep-Alive Content-Length: 170457 Content-Type: multipart/form-data; boundary=----------HCnR65lo15kSYiPLN9Rgw9....------------HCnR65lo15kSYiPLN9Rgw9 Content-Disposition: form-data; name="file"; filename="XXXXX.png" Content-Type: image/png
<AQUI LA IMAGEN> Muchos campos de la cabecera son innecesarios, pero bueno, te la pongo entera. Y bueno, como dijo jednak, la imágen abrela desde el programa, y ve enviando su contenido, no la abras como txt y la copies ni nada así jaja PD: Si la abres, abrela como BINARIO.
|
|
|
3535
|
Programación / Desarrollo Web / Re: Como ver un request HTTP?
|
en: 9 Febrero 2014, 01:33 am
|
POST /Proyectos/Uploads/uploader.php HTTP/1.1\nhost: localhost Tengo entendido que no importa en algunos servidores enviarles \n sin el \r, pero podrías probar: POST /Proyectos/Uploads/uploader.php HTTP/1.1\r\nHost: localhost EDITO: Si no te va, prueba acambiar localhost por tu IP local.
|
|
|
3537
|
Programación / Programación C/C++ / Re: Programa que identifique que tipo de dato se introduce C++
|
en: 8 Febrero 2014, 21:49 pm
|
Se puede hacer, pero tendrías que comprobar la cadena a ver si se puede convertir. Despues de saber si se puede convertir, tendrías que convertirla. Aquí te pongo un par de códigos: Saber a que tipos de dato se puede transformar:#include <iostream> using namespace std; enum type{ /** TYPES **/ type_bool = 0b000000000001, type_char = 0b000000000010, type_uchar = 0b000000000100, type_short = 0b000000001000, type_ushort = 0b000000010000, type_int = 0b000000100000, type_uint = 0b000001000000, type_llong = 0b000010000000, type_ullong = 0b000100000000, type_float = 0b001000000000, type_double = 0b010000000000, type_ldouble = 0b100000000000, /** OTHER **/ type_signed = 0b111010101011, type_unsigned = 0b000101010100, type_all = 0b111111111111 }; bool allNumeric(string s){ for(int i=0; i<s.size(); i++) if(s[i]<48 || s[i]>57) return false; return true; } bool minorEqual(string a, string b){ if(a.size()<b.size()) return true; if(a.size()>b.size()) return false; if(a==b) return true; for(int i=0; i<a.size(); i++) if(a[i]<b[i]) return true; else if(a[i]>b[i]) return false; return true; } int typeOf(string s){ if(s=="") return 0; int type = 0; bool sign = false; /** BOOL **/ if((s.size()==1 && (s[0]=='0'||s[0]=='1'))||(s.size()==4 &&s.substr(0, 4)=="true")||(s.size()==5 &&s.substr(0, 5)=="false")) type+=type_bool; /** CHAR && UCHAR **/ if(s.size()==1) type+=type_char+type_uchar; else{ if(s[0]=='-') sign=true; if(s.size()<4+sign && allNumeric(s.substr(sign, s.size()))){ if(sign){ if(minorEqual(s.substr(1, s.size()), "128")) type+=type_char; }else{ if(minorEqual(s.substr(0, s.size()), "127")) type+=type_char; if(minorEqual(s.substr(0, s.size()), "255")) type+=type_uchar; } } } /** SHORT && USHORT **/ if(s[0]=='-') sign=true; if(allNumeric(s.substr(sign, s.size()))){ if(sign){ if(minorEqual(s.substr(1, s.size()), "32768")) type+=type_short; }else{ if(minorEqual(s.substr(0, s.size()), "32767")) type+=type_short; if(minorEqual(s.substr(0, s.size()), "65535")) type+=type_ushort; } } /** INT && UINT **/ if(s[0]=='-') sign=true; if(allNumeric(s.substr(sign, s.size()))){ if(sign){ if(minorEqual(s.substr(1, s.size()), "2147483648")) type+=type_int; }else{ if(minorEqual(s.substr(0, s.size()), "2147483647")) type+=type_int; if(minorEqual(s.substr(0, s.size()), "4294967295")) type+=type_uint; } } /** LONG && ULONG **/ if(s[0]=='-') sign=true; if(allNumeric(s.substr(sign, s.size()))){ if(sign){ if(minorEqual(s.substr(1, s.size()), "9223372036854775808")) type+=type_llong; }else{ if(minorEqual(s.substr(0, s.size()), "9223372036854775807")) type+=type_llong; if(minorEqual(s.substr(0, s.size()), "18446744073709551615")) type+=type_ullong; } } double b=atof(s.c_str()); float a=(float)b; bool is=false; if(b==0.0 && (s=="0"||s=="0.0")){ type+=type_float+type_double; }else if(b!=0.0){ type+=type_double; if(a==b) type+=type_float; } return type; } int main(){ string s; getline(cin, s); if(typeOf(s)&type_int) cout << "Se puede transformar en un entero (signed)." << endl; cin.get(); return 0; }
Ejemplo de como transformar string a int:int potencia(int n, int b){ int temp=1; for(int i=0;i<b;i++) temp=temp*n; return temp; } int parseString(string s){ string a; int num = 0; for(int i=s.length()-1;i>=0;i--){ if(!((int)s[i]>=48 && (int)s[i]<=57)) return 0; num+=((int)s[i]-48)*(potencia(10, s.length()-i-1)); } return num; }
Bueno, aún no acabé con las funciones para transformar de string a numérico. Igualmente, puedes usar las funciones atol(string) Retorna un LONG, atof() Retorna un DOUBLE, atoi() Retorna un INTEDITO: Me olvidé decir, que el FLOAT, de la función typeOf(string), no funciona. Pero funciona para double.
|
|
|
3538
|
Programación / Programación C/C++ / Re: Programa que identifique que tipo de dato se introduce C++
|
en: 8 Febrero 2014, 16:08 pm
|
Me pongo a esto: enum type{ type_signed = 1, type_bool = 2, type_int = 4, type_short = 8, type_float = 16, type_double = 32, type_char = 64 /* ... */ } int typeOf(string s){ /** Esto retornará un entero compuesto de los números que pueda ser. Si es "12", por ejemplo, puede ser short, int, float, double y char. Entonces, retornaría: 4+8+16+32+64. (Puede ser más tipos, pero aun estoy empezando el enum jaja **/ }
Luego, la salida de typeOf se parsearía así: if(typeOf(str)&type_double) double d = parse<double>(str);
la función parse podría tener un template para retornar el tipo indicado xD EDITO: Como es diferente el tamaño de un signed al de un unsigned (el tamaño máximo), quitaré el type_signed, y pondré type_uchar, type_uint etc etc EDITO 2: Finalmente: enum type{ /** SIGNED TYPES **/ type_bool = 0b0000000000000001, type_char = 0b0000000000000010, type_short = 0b0000000000000100, type_int = 0b0000000000001000, type_llong = 0b0000000000010000, type_float = 0b0000000000100000, type_double = 0b0000000001000000, type_ldouble = 0b0000000010000000, /** UNSIGNED TYPES **/ type_ubool = 0b0000000100000000, type_uchar = 0b0000001000000000, type_ushort = 0b0000010000000000, type_uint = 0b0000100000000000, type_ullong = 0b0001000000000000, type_ufloat = 0b0010000000000000, type_udouble = 0b0100000000000000, type_uldouble = 0b1000000000000000, /** OTHER **/ type_signed = 0b0000000011111111, type_unsigned = 0b1111111100000000, type_all = 0b1111111111111111 };
RE-EDITO: Ahora me dió pereza poner toodos los "if" para comprobar cada tipo jaja. Si alguien se anima, aunque sea para 1 tipo solo, que postée :3
|
|
|
|
|
|
|