Socket communication with HTTP server : how to send a form variable ?
Hi everyone,
I'm trying to program a Socket application that calls a CGI programmed in ASP and sends a variable with some content via the POST HTTP method.
My problem is that I'm unable to retrieve my variable content in the CGI. I don't know what I'm doing wrong when sending my variable. Here are the main steps of my application
[Client side]
- Create an URL
- Open a connection
- Send header info with variable name and content via POST method
- Read server response
[Server side]
- Request the variable
- Store its content in a file
Here's the code of my class :
import java.net.*;
import java.io.*;
public class SocketTest{
public static void main(String args[]){
//create the URL
URL url = null;
String strURL = "http://192.168.1.11/htmleditor/cgi.asp";
try{
url = new URL(strURL);
catch(MalformedURLException exc){
System.out.println("Invalid URL : " + strURL);
//create a socket
Socket socket = null;
try{
int port = url.getPort();
if (port < 0){
port = 80;
socket = new Socket(url.getHost(), port);
catch(Exception exc){
exc.printStackTrace();
OutputStream out = null;
InputStream in = null;
try{
//configure request
String data = "htm_content=toto";
String request = "POST "+ url + " HTTP/1.0\r\n" +
"Accept: */*\r\n" +
"Content-length: " + String.valueOf(data.length()) + "\r\n" +
"Host: JAVA_HOST\r\n" +
"User-Agent: Generic\r\n\r\n" +
"htm_content=toto";
//send request
out = socket.getOutputStream();
out.write(request.getBytes());
out.flush();
//read server response
in = socket.getInputStream();
int bufferSize = 1024;
byte responseBytes[] = new byte[bufferSize];
while ((bufferSize = in.read(responseBytes)) > 0){
System.out.print(new String(responseBytes, 0,bufferSize));
catch(IOException exc){
System.out.println(exc);
//Close streams and sockets
try{
in.close();
catch(IOException exc){
exc.printStackTrace();
try{
out.close();
catch(IOException exc){
exc.printStackTrace();
try{
socket.close();
catch(IOException exc){
exc.printStackTrace();
}Here's the code of my ASP CGI page (called cgi.asp) :
//CGI.ASP - Begin
<%
Option Explicit
Dim objFso, objFile, strHtmContent, strFileName
On Error Resume Next
Set objFso = Nothing
Set objFile = Nothing
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
strFileName = Server.MapPath("htm_content.htm")
Set objFile = objFso.CreateTextFile(strFileName, True)
strHtmContent = Request("htm_content")
If len(strHtmContent) > 0 Then
objFile.Write strHTMContent
Else
objFile.Write "NO CONTENT RECEIVED"
End If
%>
<html>
<head>
<script language="javascript">
function closeAll()
window.close();
return 0;
</script>
<body onLoad="javascript:closeAll();">
</body>
</html>
//CGI.ASP - ENDWhen I execute my SocketTest app I get this output:
F:\JavaDev\htmleditor\docs>java SocketTest
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Fri, 12 Jul 2002 15:31:56 GMT
Connection: Keep-Alive
Content-Length: 192
Content-Type: text/html
Set-Cookie: ASPSESSIONIDQQGGGKMU=MMPPMLEDGDEMCCJDBGOKMNDC; path=/
Cache-control: private
<html>
<head>
<script language="javascript">
function fermerTout()
window.close();
return 0;
</script>
<body onLoad="javascript:fermerTout();">
</body>
</html>
The file "htm_content.htm" is created but it has this content :
NO CONTENT RECEIVED
This means the server was unable to retrieve the content of the variable called "htm_content"
REM : the variable is called like this 'cause I intend to use it to send HTML content
Any idea of what I'm doing wrong ?
Thanxs in advance for any help,
Diego TERCERO
For the POST request you'll only need (with HTTP 1.0)
String request = "POST "+ url + " HTTP/1.0\n" +
"Content-type: application/x-www-form-urlencoded\n" +
"Content-Length: " + String.valueOf(data.length()) + "\n" +
"\n" +
data;
Note the Content-type header.
Fred (Donne les duke�)
Similar Messages
-
Interesting! C client socket communicating with java server sockets after..
Hi,
I have a client(in C) open a socket and server(in java; jvm 1.2) listening on the same port(e.g. 4444) accepts the request and establishes a socket conn. Now the sockets are kept open indefinitely. If I kill the server process and bring it backup, the client(in C) cannot communicate with the server(in java).
Why would this be happening? Aren't the server socket garbage collected?
How do I make sure that the next time I bring up the server again, the client communicates with it.
Any inputs is really appreciated.
thanks
atul.Check the client is closing the connection before it stops.
I've had similar problems with JDBC before where if you don't explicitly close the connection it remains bound to the port, hence if your client only ever tries to connect to that port it will fail.
I think.
MrChris -
When I try to access GameCenter on my Mac it says "The requested operation could not be completed due to an error communicating with the server." How can I fix this?
This usually caused by a customised hosts file.
These need to be the only entries in your /etc/hosts file:-
# Host Database
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
Remove anything below these entries, then try and reconnect with GC. Once GC starts properly you can put the extra entries back in your hosts file, GC should start normally afterwards.
https://discussions.apple.com/message/19276629#19276629
Jerry -
good day !!! I am trying to create a new presentation in keynote,
when selected sends me the following message: An error occurred while communicating with the server, try again later. I tried for
several days to make the presentation but I keep sending the same message. I'm trying to make it from the keynote
beta (from iCloud)This is the Mac discussion, post your issue in the iWork iCloud discussion where folks who use iCloud can help you.
iWork iCloud Discussion -
Error on timesheet submission "An error occurred while communicating with the server.
Hello, we have many users who are encountering errors submitting timesheets following our migration to Project Server 2013 (SP1 April 2014 CU). The error is:
An error occurred while communicating with the server. Check connectivity with your administrator to determine whether further action is necessary.
This follows the specific timesheet, if I open a delegate session on my machine, I can reproduce the error. However, simply deleting and recreating the timesheet has resolved it for many users, at least until the next timesheet submission.
Has anyone seen this sort of widespread behavior and have a solution beyond deleting and recreating the given timesheet?
Thanks!Hello Joncantrell
I just ran into issue and found a way to resolve, though it may not be the best. I think it is a bug, but here is how I fixed it.
1) Delegating as the user
2) Deleted the timesheet
3) Going line by line, I check each task that had a status of "Not Submitted" and "Send Progress for Select Task".
4) The error came up only for one task.
5) Open that schedule, remove resource from task, saved and published.
6) Deleted and recreated timesheet
7) Submitted timesheet and processed normally.
I hope this helps
Cheers!
Michael Wharton, MVP, MBA, PMP, MCT, MCTS, MCSD, MCSE+I, MCDBA
Website http://www.WhartonComputer.com
Blog http://MyProjectExpert.com contains my field notes and SQL queries -
Hello, lately i noticed dw 5.5 can't seem to use browserlab, it says "Your network preferences prevent us from communicating with the server"
I can connect to BC and other ftp servers no problem, I've also turned off my firewall to be sure and it still won;t connect.
The only info I found on this error is a tip on how to turn off browserlab, which in turn gets this error, Not sure why you would wnat to shut the feature off, but no tip to turn it on. The tip on editing the registry doesn;t help because itsyays to change the registry key to 0 and all communication of adobe products will be turned off, however the key does exist and is set to 1, so I can;t even try that tip in reverse to enable, itshould be communication already.
Any help would be appreciated, I am just competinga site and was about to check it in all the browsers, an incredibly useful and time saving feature, but I can't now.
RichPhil, the only screenshot I've seen from you is the error message (and I can't seem to view the others you just posted), so apologies if I told you something you'd already tried. We still think there should be a solution to this, it's just that debugging issues this way can be a little difficult, so please bear with us.
At this point our best guess is that there is a registry setting that got changed that is causing the issue for both of you. We have been able to repro the issue on Windows XP by setting the following 32-bit registry entry to 0. The issue was fixed by changing it back to 1. We've also tested on Windows 7 and verified the same thing with the 64-bit registry entry. Apologies if I'm suggesting something that any of you has already tried, but no details were provided about which registry entry you checked or what article you were looking at.
From the CSLive team:
"To my knowledge the only way to get that error message is to disable CSLive in the registry. The Customer does not mention the exact article or reg value that he is looking at in his post but it should be:
For 32-bit systems: HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\AdobeOnlineDefault.
For 64-bit systems: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Adobe\AdobeOnlineDefault
http://kb2.adobe.com/cps/846/cpsid_84665.html
He should delete the AdobeOnlineDefault entry in the registry and try again. (he may need to stop and restart CS55Services Manager or reboot machine)."
Let us know if this fixes the issue for you or not. As with any change to the registry we recommend you make a backup first and proceed carefully.
Thanks,
Mark -
Error occured while communicating with web server
In Netweaver if you receive this error " error occured while communicating with web server "
check your script logic file if you have mande any change to dimension
names
VinooHi,
validate below note
Note 1330145 - an error occured while communicating with the web server
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/b161a590-0201-0010-5590-91fa5076a914
regards
nag -
Error while communicating with the server
Hi Experts,
I'm having the following issue, when I try to send data using an input schedule the server says that there was an error while communicating with the server and don't send the data, I took a look at the log file and it says the following,
==============[BPC Logging]==============
[Message Type] : ERROR
[Job Name] : OSoft.Services.Application.FileAccessService.FileAccessServiceProxy
[DateTime] : 4/6/2011 8:42:44 AM
[UserId] : CAMESAP\BPC_SYSADMIN
[Message] : UJF_EXCEPTION E018 Cannot find document/directory 0
==============[BPC Logging End ]==============
Also i went to take a look at the default script logic, because i remember that this error happened to me when i wrongly program an script logic in the default.lgf but it shows me the following error when I open it,
System.InvalidCastExeption: Specified cast is not valid
at System.data.DataColumnCollection.get_Item(String name)
at System.data.DataRow.get_Item(String columnName)
at Osoft.Consumers.Admin.AdminLogicClient50.LogicMain.GetLogic()
If I compile the file, the error stop appearing, put with all new logic files it happens at first, I think that these two errors are very deep related, if anyone can help me will be very appreciated,
Thanks in advancedHi,
I have faced the similar kind of problem in BPC NW 7.5 SP5.
The main reason is when you are trying to send any data via input schedule, you will get this web server communication issue.
1) Check if any thing you are calling script logic under default.LGF. Exclude the logic out from default and test it.
2) Process all the dimensions in application
3) Perform Lite optimization and check are there any errors.
4) Finally check BPC COM+ services and check if any service stopped and also check osoft send governer service in microsoft services.
5) Diagnoise usign server manager.
6) Try input some thing in apshell and check if u face the same web server communication error? -
I have a simple form which allows users to submit receipts as attachments. I have some required identifying information (name, etc.) and then three optional slots for attachments, along with optional text boxes for descriptions. The form tests fine with attachments on my computer and on a couple other computers we tested with.
However, I am getting complaints from several users that they see the following message when they hit "Submit": "An error has occurred. There was an error communicating with the server. Please try again later." Any ideas why this might be or how I can fix it?Do you mind emailing the URL of your fillable form to me ([email protected]).
I would like to investigate as to what the issue might be with Internet Explorer.
Sorry for the inconveniences.
Gen -
Error communicating with AdobeID server - DAY 3
So, I'm trying to activate the Digital Editions of Adobe on my MacBook, but I keep getting this darned message:Error communicating with AdobeID server. Please try again later.
What in the world is happening? I've been trying to get this to work for nearly 3 days. My classes will begin soon, and I'm REQUIRED to have this Adobe Digital Editions in order to download my books. WTH?! Can someone please help me get around this problem please?
Thank,
MoniqueI'm getting the same problem. I'm in the UK
My error message is: E_AUTH_DATABASE_CONSISTENCY http://adeactivate.adobe.com/adept/SignInDirect AdobeID
(I have removed my ID) -
UNCAUGHT_EXCEPTION - communication with BW server
Hi,
I am getting an error UNCAUGHT_EXCEPTION which is due to communication with BW server. I get this while trying to define a local formula.
When i try to do the same activity with another user id, this does not happen.Is it becouse of authorization. If yes how can i find which authorization object is really creating problem ?
Regards,
Bill
Edited by: Bill Bryan on Jun 23, 2008 11:51 AMauthorization trace should give you information about what objects you are missing...
ST01 and check authorization check ..activate trace...and run whatever you were doing and check the trace log..
or you can ask the basis guy to make your authorization profile same as your colleague with whose id it was working... -
"Error communicating with AdobeID server"
Every time I try to authorize my ADE, I keep getting this error message:
"Error communicating with AdobeID server. Please try again later.
E_ADEPT_IO AddSignInDirect Error%20#2032"
I've tried to authorize it more times than I can count over the past few weeks - anyone know what I can do to fix it?
It used to work just fine, but then I started getting error messages on any books I tried to download and nothing I did would fix it, so I tried uninstalling then reinstalling and it won't let me authorize it now (I tried authorizing with a different ID too, to see if that was the problem but it wouldn't work).Hi,
As per the error message that you are getting E_AUTH_BAD_DEVICE_KEYplease follow the steps as given below.
1) Open Adobe Digital Editions.
2) Press Ctrl+Shift+D key of your Keyboard and deauthorize Digital Editions
3) Move your e-books to some different Location.
4) uninstall Adobe Digital Editions from your computer.
Click start>>Control Panel>>Add or remove Program
Select Adobe Digital Editions from the list and Delete.
5) Also delete following files.
Click Start>>Run
Type "regedit" without quotes in the box and hit enter.
Locate the following key "HKEY_CURRENT_USER>Software>Adobe>Digital Editions"
delete the full folder (Right click on it and click delete).
Also locate HKEY_CURRENT_USER>Software>Adobe>Adept
Delete the full folder.
6) Now download and install Adobe Digital Editions from the link given below.
http://www.adobe.com/products/digitaleditions/
7) When asked to authorize computer then please enter same Adobe ID and password and authorize the same.
I hope this will help you!!!
Regards
Rizwan -
Kind day, colleague.
It was required to organize a statement chain for TimeSheet of employees, as we realized. Everything is good, but at linear managers in PSW opportunity to execute Approve when viewing TimeSheet of the employee remained, and in attempt to approve TimeSheet there
is a mistake.
500 Internal Server Error
"An error occurred when communicating with the server. Check connectivity with your administrator to determine whether further action is necessary. "
Accept, is carried out as it is necessary.
It is a bug or we not correctly realized approval chain?issue is related to the user booking time against a task that was past the finish/end date listed in the Project Schedule.
To resolve the user needs to submit their time on a valid task that is still within the current reporting timeframe, or have the Project Manager
update the task in questions so that the finish/end dates are at or beyond the submission period and then republish the project. After that, the user should be able to go in and submit their timesheet with success.
http://patrickdrews.com/2012/09/project-server-2010-timesheet-submission-produces-an-error-occurred-while-communicating-with-the-server/
kirtesh -
An Error Occurred While Communicating with Web Server
We are getting an error message ("An Error Occurred While Communicating with Web Server") when sending data from BPC Excel. Any one konws why it is coming.
We are using ASP.NET version 2.0.50727 in ISS ServerHi,
This kind of error happens when EVDRE status is not Ok.
Even if EVDRE status is OK please make the relevant changes in expansion range--> MemberSet values.
Hope it helps
Raman
Edited by: Radharaman Singh Rajkumar on Jun 29, 2010 5:25 PM -
Activate change lists error - Communication with JMS server failed
Hi,
I have this error message prompted when I try to activate my design object in Integration Builder :-
<i>Communication with JMS server failed Repeat the last action. If the problem continues to occur after multiple attempts, contact your system administrator to check the availability of the JMS provider service.</i>
Anyone knows where should I fix the errors ? Many Thanks in Advance.
regardsHi,
I think you should check the JMS Provider service in the Visual Administrator.
Have a look at those help pages:
<a href="http://help.sap.com/saphelp_nw04/helpdata/en/90/57849e5e3e45d784afc4e3bfa8136f/frameset.htm">JMS Administration</a>
<a href="http://help.sap.com/saphelp_nw04/helpdata/en/a9/ad3d9ef22e4b2ea9752de8d98db5a4/frameset.htm">JMS Provider Service</a>
Best regards,
Manuel
Maybe you are looking for
-
Ipad mini did update and now screen rotation is locked.. can this be fixed ?
I did and update for ipad mini and now the screen rotation is locked. I am seeing other posts about this update and am afraid this will be step one in more issues. Afraid to do the upgrade on my mac. Last time I had to take it in to the genius bar to
-
Java Problems With Some Applications
Ever since I updated Java Web Start at the end of September I've had problems getting some applications to open correctly. I know that's the problem too because it happened right after I did the update. I updated, restarted the computer, tried to lau
-
We have a 32 gb iPad, slow but sure. Just tried to do restore from cloud and now it's frozen. Shut off with power button and wake/sleep only and all I get is the apple symbol when I restart it. Stuck.
-
Programmable Keyboard shortcuts
This would save me so much time. I wish you could assign Fkeys to develop module presets. I also love the + and - keys for exposure. I know you can toggle through all the different sliders but by the time you have done that you may as well use the
-
How can i unlock my Iphone 4