URLConnection send data to server

I am using the following code to upload a large binary data to a http
server.
URL u = new URL(urlString);
URLConnection c = u.openConnection();
c.setDoOutput(true);
c.setDoInput(true);
c.setUseCaches(false);
// set some request headers
c.setRequestProperty(
"Connection",
"Keep-Alive");
// get codebase of the this (the applet) to use for referer
c.setRequestProperty(
"HTTP_REFERER",
codebase);
c.setRequestProperty(
"Content-Type",
"multipart/form-data; boundary=" + boundary);
DataOutputStream dstream = new
DataOutputStream(c.getOutputStream());
for (int i = 0; i < 1000; i++){
byte[] data = new byte[1000];
data = ....
dstream.write(dataq,0,1000);
dstream.writeBytes("\r\n--" + boundary + "--\r\n");
dstream.flush();
dstream.close();
I found that the data was never sent. If I put the following line after
the code above, however, the data got sent. Why?
c.getInputStream();

Thank you for your post.
I have another question. If the data is not update until I call c.getInputString(), how can I monitor the progress of the upload and display the progress with a JProgressBar?
Thanks,

Similar Messages

  • Send data from server to multiclient

    ServerSocket s = new ServerSocket(9999);
    Socket incoming = s.accept();
    BufferedReader data_in = new BufferedReader(new InputStreamReader(incoming.getInputStream()));
    PrintWriter data_out = new PrintWriter(incoming.getOutputStream());
    data_out.println("connected");
    data_out.flush();the data_out.println will send the data to all connected client right?

    No, it will send data to the single client that is
    connected with that socket.
    Read the tutorials.thanks..
    if the server is connected with multi client using same port.. then the data also will send to single client?

  • Best way to send data to server?

    Hi,
    I'm sending the usual info (name, email, address, city &
    zip) from flex to a PHP script which then emails that data to me
    and I was wondering if I should send each separately (
    variables.name = name.text ) and format it in php to send to me or
    should I format all the data in flex and send it as one lump to php
    ( variables.client, where client has all the above data formated in
    the way I need )? Which would be the best or doesn't it matter?
    Thanks,
    Paul

    Send it all at once. Why not?
    Tracy

  • Strange ClassNotFoundException while sending data to Server

    hi
    i'm trying to send an object to the server, but im getting a
    java.lang.ClassNotFoundException: [[L[/b]app.brk.report.ReportField
    at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    notice the "[b][[L[/b]" in the exception message,
    my class is app.brk.report.ReportField, wonder where the "[b][[L[/b]" came from
    Any suggestions or help is much appreciated,
    thanks

    Hi,
    Using Operational Insights from North Europe is supported, and we will soon also have an instance of the service running in Europe.
    Error 12002L that you are seeing indicates a timeout.
    Do you use a proxy to access the internet? If so, the agent proxy settings should be set.
    You can access the proxy settings for the agent from the control panel - look for the Microsoft Monitoring Agent.
    Kind Regards
    Richard
    This posting is provided "AS IS" with no warranties, and confers no rights.

  • Send data BPC 5.1 very slow because Antivirus Kaspersky

    Dear All....
    I have problem with BPC 5.1, the problem when send data to server (send and refresh schedule ). The prosses send data is very slow. I think its because antivirus (Kaspersky), when protection is enable, prosses send data very slow. But when i turn off the protection, prosses send data faster...
    The problem is imposible if i turn off protection to every client.
    So, what the object, file, application, macro or rule must i exclusion (unscan) with antivirus??
    I have already give exclusion to file Ev4DMMPM.xla, but sometime its work, sometime not...
    Please help...
    Best regards,
    Dharma Setiadi

    Dear all...
    Thanks for attention.....
    I have already exclusion folder BPC but still not work. But i think the problem with  port. I try turn off scanning with port 80 and its work. I never find slow again...
    But the problem, i can't turn off scanning with port 80, its about security. How about if i change port 80 for BPC..?? What is impact with server and with client..?? And whatever that must be noticed in this port changing..?? setting server manager..??
    Note : i used multi-server configuration...
    Best Regards,
    Dharma Setiadi

  • Delaying send data until event occurs

    Hii all,
    I'm new to java socket programing.
    i'm trying to develop simple system using TCP socket for client server communication over a network. I use AWT for user interfaces.
    The client program is supposed to get two inputs from user via 2 Text fields and send those to server.
    In my client program i have a method to listen server socket send data to server and inner class for user interface thing and i have called those 2 in main method consecutively.
    I want to delay calling listenSocket() method until the user click submit button. i think i have to use some synchronized methods but i dont have much idea of how to do it.
    I have attached the code here.
    Can anybody help me plzzzz? any suggestions would be appreciated.
    public class Client {
    /*for TCP socket connection*/
    Socket clientSocket=null;               
    PrintWriter out = null;          
    BufferedReader in = null;
    private String accountNo =null;
    private String accountType =null;
    public static void main(String[] srgs) {
    Client client =new Client();
    CustomerRequestUI requestUI =client.new CustomerRequestUI();
    client.listenSockect();
    public void listenSockect() {
    try {
    clientSocket = new Socket("localhost", 1234);
    out =new PrintWriter(clientSocket.getOutputStream(),true);
    out.println(accountNo);
    out.println(accountType);
    } catch (UnknownHostException e) {
         // TODO Auto-generated catch block
         System.out.println("Unknown host: localhost");
         e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
         System.out.println("No I/O");
         e.printStackTrace();
    class CustomerRequestUI extends Frame implements ActionListener{
              //declare components
              Label accNumLabel     =null;
              Label accTypeLabel     =null;
              TextField accNumText =null;
              TextField accTypeText=null;
              Button submitButton     =null;
              Button closeButton =null;
         public CustomerRequestUI(){
              this.setTitle("Customer Request");
              this.setLayout(new GridLayout(3,2));
              this.setBackground(Color.lightGray);
              accNumLabel =new Label("Account Number");
              accNumText =new TextField(10);
              accTypeLabel =new Label("Account Type");
              accTypeText =new TextField(25);
              submitButton =new Button("Submit");
              closeButton =new Button("Close");
              //add components to frame
              this.add(accNumLabel);
              this.add(accNumText);
              this.add(accTypeLabel);
              this.add(accTypeText);
              this.add(submitButton);
              this.add(closeButton);
              //add ActionListener to components
              accNumText.addActionListener(this);
              accTypeText.addActionListener(this);
              submitButton.addActionListener(this);
              closeButton.addActionListener(this);
              this.pack();
              this.show();      
         public void actionPerformed(ActionEvent event) {
         Object source =event.getSource();
         if(source ==submitButton){
              accountNo =accNumText.getText();
              accountType =accTypeText.getText();
         if(source ==closeButton){
         this.setVisible(false);                    this.dispose();
         System.exit(0);                    
    }

    If you want to listenSocket after a user clicks submit, why don't to call listenSocket when the use clicks submit.

  • Send data buttom

    Hi Gurus,
    What is MNU command to send data to server and also for modify work status.
    Regards,
    Reddy.

    Hi,
    these are the cmds for sending data:
    MNU_eSUBMIT_REFSCHEDULE_SHEET_NOACTION
    Sends data without clearing or refreshing.
    MNU_eSUBMIT_REFSCHEDULE_SHEET_CLEAR
    Sends data and clears input cells.
    MNU_eSUBMIT_REFSCHEDULE_SHEET_REFRESH
    Sends data and refreshes the worksheet.
    MNU_eSUBMIT_REFSCHEDULE_SHEET_CLEARANDREFRESH
    Sends data and clears and refreshes the worksheet.
    MNU_eSUBMIT_REFSCHEDULE_BOOK_NOACTION
    Sends data without clearing or refreshing the worksheet.
    MNU_eSUBMIT_REFSCHEDULE_BOOK_NOACTION_SHOWRESULT
    Sends data without clearing or refreshing the worksheet, and shows the result in a window upon successful send.
    MNU_eSUBMIT_REFSCHEDULE_BOOK_CLEAR
    Sends workbook and clears data.
    MNU_eSUBMIT_REFSCHEDULE_BOOK_REFRESH
    Sends workbook and refreshes data.
    MNU_eSUBMIT_REFSCHEDULE_BOOK_CLEARANDREFRESH
    Sends workbook and clears data and refreshes workbook.
    MNU_eSUBMIT_MODIFY
    Opens the work status action pane in BPC Web
    thnks.
    Edited by: Sakthi Jaganathan on May 27, 2009 5:07 PM

  • Send data from applet to web server

    Hi,
    I want to send data(event notification) to resource through web server using url.
    Like,As long as perticular action or event is occuring I am sending that message to url.
    I reffered Sevlet theory uses HTTPMessage,but I am confused how should start and what would be feasible?
    Even when I run my code I am not finding browser.How should I place an applet in web server page?
    Regards,
    Palak
    Message was edited by:
    palak_shah

    Hi
    I agree usage of HttpClient is a better and a simple method.
    But If your Application Requirements are Simple you may go by using URL & URLconnection Objects in java.net package.
    Just to Add In You Can Checkout the links given below to have a better understanding of how the communication works...
    The Example APPLET code:
    http://mindy.cs.bham.ac.uk/AppletServletExample/EgApplet.java.txt
    The Example SERVLET code:
    http://mindy.cs.bham.ac.uk/AppletServletExample/EgServlet.java.txt
    and the Example AppletDemo Class
    http://mindy.cs.bham.ac.uk/AppletServletExample/EgApplet.class
    Hope this helps :)
    REGARDS,
    RaHuL

  • I would like to use DDE to send data from a Lookout Server to an Excel

    Hello National Instruments,
    I would like to use DDE to send data from a Lookout Server to an Excel
    Spreadsheet.
    I have Lookout 6.1 on a server connected to 4 client workstations
    The operating system on the server is Windows Server 2003 R2; Standard Edition;
    Service Pack 2
    I have opened DDE Share but after filing in Share Name; Static Application
    Name; Static Topic Name
    I get a message, "Can't bind to DSDM service"
    I also get this message when I press add a Share
    What are the steps to setting up this type of communications link?
    Thanks,
    David Lopez
    Scada Functional Analyst

    Ryan,
    I have followed the steps on the Knowledge Base "How do I use DDE To Send Data Across the Network To Excel From Lookout?" but what I am seeing is that the computer with excel (Computer B)hangs up displaying an hour glass continuously leaving me no option but to go into task manager to stop excel.  It appears to me that the dde share is not working properly on my windows xp where lookout resides or I do not have a certain service turned on.  I do have the DDE services turned on both computers.  I have my computer set up as computer A with Lookout and Process1 as the process with a pot set up as pot1.  On my computer (Computer A) I also have the dde share set up per the KB example.
    On computer B I have the dde services turned on and I am typing the following into an excel worksheet Cell  ='\\TAG23232\NDDE$'|'Process1$'!Pot1
    TAG 23232 is Computer A's Name
    Do you have any suggestions???

  • In JDBC Sender Adapter , the server is Microsoft SQL .I need to pass current date as the input column while Executing stored procedure, which will get me 10 Output Columns. Kindly suggest me the SQL Query String

    In JDBC Sender Adapter , the server is Microsoft SQL .I need to pass current date as the input column while Executing stored procedure, which will get me 10 Output Columns. Kindly suggest me the SQL Query String , for executing the Stored Procedure with Current date as the input .

    Hi Srinath,
    The below blog might be useful
    http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/03/06/executing-stored-procedure-from-sender-adapter-in-sap-pi-71
    PI/XI: Sender JDBC adapter for Oracle stored procedures in 5 days
    regards,
    Harish

  • I want to send data from One server to another

    Hi all,
    My requirement to send data from one server's  application server path(data in one directory in Al11 of the source server) to another server's application server(TO another directory in Al11 transaction of the destination server).
    What are all the ways to achieve this task.
    Thanks in Advance.
    Raja

    While the FTP option mentioned above is workable, both servers should have some form of FTP service running with reference to this solution.
    I suggest two more options, just to give you an idea. I am not getting into details as it is important to get the big picture first before working on details.
    1: Through RFC destinations:
    You can define two RFc destinations, each pointing to the specific application server. Assuming the server names are SOURCE and TARGET, you can have two RFC destinations where you differentiate the servers by specifying the host name or IP address.
    Once the destinations are defined, you need to develop two RFC enabled function module, one will be used to read the file and return it in form of internal table. The other will be get the internal table as input and should save it on server (using abap commands open dataset etc.)
    Now you can have an ABAP program where you first call the function which is reading the file. In call function you mention the RFC destination of source server.
    Once the file is read, you than call the second function module with destination to target server and save the internal table to a file.
    2: Through Background job programming
    While scheduling a background job, you can specify target system which forces the background job to run on that target application server. The basic idea here is to have two abap programs, one would be used to read file and export it to database table like INDX (we can call it ZPRG1), the other will import from the table INDX and write it as a file (we can call it ZPRG2).
    Now you can define a job through SM36, using ZPRG1 as program, and target system as the first application server. This job you can schedule to run periodically.
    Also define a second job through SM36, using ZPRG2 as program and target system as the second application server. For this job, the starting condition you can put as ‘After completion of job1’.
    Another method one can be by using FMs used in tcode SM49 but for that I think your sysadmin might have to create a batch file/script first. Which you can later call from ABAP.
    Cheers.

  • Error 61 when sending data from client and back from server.vi

    Trying to generate and send a data from client.vi and adding the numbers generated and sending it back to the client .In client the data is received only once and an error 61 occurs .How do I get rid of this error?I have attached the two files for reference
    Attachments:
    Sguruserver.vi ‏63 KB
    client1.vi ‏100 KB

    You can certainly use and application started by WebStart to send data to a server.
    However, the Sandbox restrictions allow you to contact the server the application was loaded from without asking for permission first (i.e. signing your application and requesting the proper permissions in your JNLP file).
    The JNLP BasicService can be used to retrieve the URL (and therefore the server) the application was loaded from.

  • How to send data back to the server

    i create a program to send data back to ther server using j2me.
    its work well on emulator but when i install the application on sony ericsssin p910i or k700i or nokia 7710 then its not working and simply hang.
    here is sample code which is run well on emulator but not on mobile.
    what is the problem in that or how can this code run in mobile is there any mobile specific setting or internet setting.
    Pls reply asap.
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * An example MIDlet to invoke a CGI script.
    public class ThirdExample extends MIDlet {
    private Display display;
    // String url = "http://www.javacourses.com/cgi-bin/getgrade.cgi?idnum=182016";
    String url = "http://sampler.infopro.stpn.soft.net/midletdata.asp?name=name";
    public ThirdExample() {
    display = Display.getDisplay(this);
    * Initialization. Invoked when we activate the MIDlet.
    public void startApp() {
    try {
    getGrade(url);
    } catch (IOException e) {
    System.out.println("IOException " + e);
    e.printStackTrace();
    * Pause, discontinue ....
    public void pauseApp() {
    * Destroy must cleanup everything.
    public void destroyApp(boolean unconditional) {
    * Retrieve a grade....
    void getGrade(String url) throws IOException {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    StringBuffer b = new StringBuffer();
    TextBox t = null;
    int x = 5, y =7;
    try {
    c = (HttpConnection)Connector.open(url);
    c.setRequestMethod(HttpConnection.GET);
    c.setRequestProperty("IF-Modified-Since", "10 Nov 2000 17:29:12 GMT");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-CA");
    os = c.openOutputStream();
    String str = "?idnum=182016";
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.writeByte(postmsg);
    os.flush();
    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1) {
    b.append((char) ch);
    System.out.println((char)ch);
    t = new TextBox("Final Grades", b.toString(), 1024, 0);
    } finally {
    if(is!= null) {
    is.close();
    if(os != null) {
    os.close();
    if(c != null) {
    c.close();
    display.setCurrent(t);
    }>

    i create a program to send data back to ther server using j2me.
    its work well on emulator but when i install the application on sony ericsssin p910i or k700i or nokia 7710 then its not working and simply hang.
    here is sample code which is run well on emulator but not on mobile.
    what is the problem in that or how can this code run in mobile is there any mobile specific setting or internet setting.
    Pls reply asap.
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * An example MIDlet to invoke a CGI script.
    public class ThirdExample extends MIDlet {
    private Display display;
    // String url = "http://www.javacourses.com/cgi-bin/getgrade.cgi?idnum=182016";
    String url = "http://sampler.infopro.stpn.soft.net/midletdata.asp?name=name";
    public ThirdExample() {
    display = Display.getDisplay(this);
    * Initialization. Invoked when we activate the MIDlet.
    public void startApp() {
    try {
    getGrade(url);
    } catch (IOException e) {
    System.out.println("IOException " + e);
    e.printStackTrace();
    * Pause, discontinue ....
    public void pauseApp() {
    * Destroy must cleanup everything.
    public void destroyApp(boolean unconditional) {
    * Retrieve a grade....
    void getGrade(String url) throws IOException {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    StringBuffer b = new StringBuffer();
    TextBox t = null;
    int x = 5, y =7;
    try {
    c = (HttpConnection)Connector.open(url);
    c.setRequestMethod(HttpConnection.GET);
    c.setRequestProperty("IF-Modified-Since", "10 Nov 2000 17:29:12 GMT");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-CA");
    os = c.openOutputStream();
    String str = "?idnum=182016";
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.writeByte(postmsg);
    os.flush();
    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1) {
    b.append((char) ch);
    System.out.println((char)ch);
    t = new TextBox("Final Grades", b.toString(), 1024, 0);
    } finally {
    if(is!= null) {
    is.close();
    if(os != null) {
    os.close();
    if(c != null) {
    c.close();
    display.setCurrent(t);
    }>

  • Send Data back to the Server

    Hi.
    how to send data back to the server using J2ME or how to communicate with server using J2ME

    i am using http its work well on emulator but when i install the application on sony ericsssin p910i or k700i or nokia 7710 then its not working and simply hang.
    here is sample code which is run well on emulator but not on mobile.
    what is the problem in that or how can this code run in mobile is there any mobile specific setting or internet setting.
    Pls reply asap.
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * An example MIDlet to invoke a CGI script.
    public class ThirdExample extends MIDlet {
    private Display display;
    // String url = "http://www.javacourses.com/cgi-bin/getgrade.cgi?idnum=182016";
    String url = "http://sampler.infopro.stpn.soft.net/midletdata.asp?name=name";
    public ThirdExample() {
    display = Display.getDisplay(this);
    * Initialization. Invoked when we activate the MIDlet.
    public void startApp() {
         try {
    getGrade(url);
         } catch (IOException e) {
         System.out.println("IOException " + e);
         e.printStackTrace();
    * Pause, discontinue ....
    public void pauseApp() {
    * Destroy must cleanup everything.
    public void destroyApp(boolean unconditional) {
    * Retrieve a grade....
    void getGrade(String url) throws IOException {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    StringBuffer b = new StringBuffer();
    TextBox t = null;
    int x = 5, y =7;
    try {
    c = (HttpConnection)Connector.open(url);
    c.setRequestMethod(HttpConnection.GET);
    c.setRequestProperty("IF-Modified-Since", "10 Nov 2000 17:29:12 GMT");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-CA");
    os = c.openOutputStream();
    String str = "?idnum=182016";
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.writeByte(postmsg);
    os.flush();
    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1) {
    b.append((char) ch);
    System.out.println((char)ch);
    t = new TextBox("Final Grades", b.toString(), 1024, 0);
    } finally {
    if(is!= null) {
    is.close();
    if(os != null) {
    os.close();
    if(c != null) {
    c.close();
    display.setCurrent(t);

  • [iPhone] How would one send data to an http server?

    Hello,
    I would like to be able to send data (maybe XML?) to be processed by a server-side script.
    NSURLRequest seems to be mainly for downloading data, not uploading... A simple "ajax" request would do, so I would just serialize the data and send it in a POST variable. How do I implement such a request using the SDK?

    This what iam doing to post XML and to receive an XML response from our servers. Note that the Content-Type is set to text/xml. If your post data is different, set the type accordingly.
    Also i am using *NSURLConnection -> sendSynchronousRequest* class method to block for the response. You can also do asynchronous read of the response by creating a NSURLConnection object and setting a delegate which will listen for the incomming network events. Check the documentation for NSURLConnection .
    Hope this helps,
    -TRS
    // This method takes an XML post data and returns the response XML from server
    // Note that if you want to post binary data then just send postData instead of
    // postString as input parameter
    - (NSString *) postData: (NSString *) postString toURL:(NSString *) url {
    NSData *postData = [postString dataUsingEncoding: NSUTF8StringEncoding];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]
    cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];
    NSURLResponse *response = nil;
    NSError *error = NULL;
    NSData *respData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSString *responseString = nil;
    if (!error && respData) {
    if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
    int code = [((NSHTTPURLResponse *)response) statusCode];
    if (code == 200) {
    responseString = [[[NSString alloc] initWithData:respData encoding:NSUTF8StringEncoding] autorelease];
    } else {
    NSLog(@"
    Error");
    } else {
    NSLog(@"
    Error");
    [request release];
    return responseString;

Maybe you are looking for